Skip to content

Commit

Permalink
GH-35112: [Python] Expose keys_sorted in python MapType (#35113)
Browse files Browse the repository at this point in the history
### 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 <aandres@tradewelltech.co>
Signed-off-by: Alenka Frim <frim.alenka@gmail.com>
  • Loading branch information
0x26res committed Apr 18, 2023
1 parent 9f852d4 commit 1deb740
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/pyarrow/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions python/pyarrow/types.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 1deb740

Please sign in to comment.