This is an automated email from the ASF dual-hosted git repository.
alenka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 1deb740e02 GH-35112: [Python] Expose keys_sorted in python MapType
(#35113)
1deb740e02 is described below
commit 1deb740e02fa928e60ce611790d9dff2d1a6077e
Author: 0x26res <[email protected]>
AuthorDate: Tue Apr 18 11:23:23 2023 +0100
GH-35112: [Python] Expose keys_sorted in python MapType (#35113)
### Rationale for this change
It not possible to read `keys_sorted` in the python API
### What changes are included in this PR?
- expose keys_sorted in `cdef class MapType` / types.pxi
- add tests
### Are these changes tested?
yes
### Are there any user-facing changes?
We're exposing keys_sorted but I guess the documentation will update itself
from the `"""` pydoc (?)
This is not an API breaking change
* Closes: #35112
Authored-by: aandres <[email protected]>
Signed-off-by: Alenka Frim <[email protected]>
---
python/pyarrow/tests/test_types.py | 4 ++++
python/pyarrow/types.pxi | 13 +++++++++++++
2 files changed, 17 insertions(+)
diff --git a/python/pyarrow/tests/test_types.py
b/python/pyarrow/tests/test_types.py
index 09f0dfe7d3..568702d8e8 100644
--- a/python/pyarrow/tests/test_types.py
+++ b/python/pyarrow/tests/test_types.py
@@ -580,6 +580,10 @@ def test_map_type():
assert ty == ty_metadata
assert not ty.equals(ty_metadata, check_metadata=True)
+ for keys_sorted in [True, False]:
+ assert pa.map_(pa.utf8(), pa.int32(),
+ keys_sorted=keys_sorted).keys_sorted == keys_sorted
+
with pytest.raises(TypeError):
pa.map_(None)
with pytest.raises(TypeError):
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index 4ad2536368..c02d036e0f 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -536,6 +536,19 @@ cdef class MapType(DataType):
"""
return pyarrow_wrap_data_type(self.map_type.item_type())
+ @property
+ def keys_sorted(self):
+ """
+ Should the entries be sorted according to keys.
+
+ Examples
+ --------
+ >>> import pyarrow as pa
+ >>> pa.map_(pa.string(), pa.int32(), keys_sorted=True).keys_sorted
+ True
+ """
+ return self.map_type.keys_sorted()
+
cdef class FixedSizeListType(DataType):
"""