From b703ecf42eea661e6c0772ef527f6fa6fb256969 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Fri, 27 Apr 2018 11:49:51 +0200 Subject: [PATCH 1/2] implement DictionaryType.index_type --- python/pyarrow/tests/test_types.py | 5 +++++ python/pyarrow/types.pxi | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py index bb2a986a352..326e2097f3f 100644 --- a/python/pyarrow/tests/test_types.py +++ b/python/pyarrow/tests/test_types.py @@ -210,6 +210,11 @@ def test_types_picklable(): assert pickle.loads(data) == ty +def test_dictionary_type(): + ty = pa.dictionary(pa.int32(), pa.array(['a', 'b', 'c'])) + assert ty.index_type == pa.int32() + + def test_fields_hashable(): in_dict = {} fields = [pa.field('a', pa.int64()), diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi index 850be23fcd5..702c83fb536 100644 --- a/python/pyarrow/types.pxi +++ b/python/pyarrow/types.pxi @@ -184,6 +184,11 @@ cdef class DictionaryType(DataType): def __get__(self): return self.dict_type.ordered() + property index_type: + + def __get__(self): + return pyarrow_wrap_data_type(self.dict_type.index_type()) + cdef class ListType(DataType): From 788179c2205457a1a797de41b5cb30d3d49b0608 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Thu, 26 Apr 2018 13:59:07 +0200 Subject: [PATCH 2/2] implement DictionaryType.dictionary --- python/pyarrow/tests/test_types.py | 1 + python/pyarrow/types.pxi | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py index 326e2097f3f..60cd5be0ad2 100644 --- a/python/pyarrow/tests/test_types.py +++ b/python/pyarrow/tests/test_types.py @@ -213,6 +213,7 @@ def test_types_picklable(): def test_dictionary_type(): ty = pa.dictionary(pa.int32(), pa.array(['a', 'b', 'c'])) assert ty.index_type == pa.int32() + assert ty.dictionary.to_pylist() == ['a', 'b', 'c'] def test_fields_hashable(): diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi index 702c83fb536..9cd9bede6e0 100644 --- a/python/pyarrow/types.pxi +++ b/python/pyarrow/types.pxi @@ -189,6 +189,11 @@ cdef class DictionaryType(DataType): def __get__(self): return pyarrow_wrap_data_type(self.dict_type.index_type()) + property dictionary: + + def __get__(self): + return pyarrow_wrap_array(self.dict_type.dictionary()) + cdef class ListType(DataType):