From 1deb740e02fa928e60ce611790d9dff2d1a6077e Mon Sep 17 00:00:00 2001 From: 0x26res Date: Tue, 18 Apr 2023 11:23:23 +0100 Subject: [PATCH] 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 Signed-off-by: Alenka Frim --- 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 09f0dfe7d37df..568702d8e888f 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 4ad2536368e3f..c02d036e0f57b 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): """