Skip to content

Commit d0d4b15

Browse files
committed
Add __reduce__ method to ExtensionType class
1 parent 0f65220 commit d0d4b15

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

python/pyarrow/tests/test_extension_type.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,13 @@ def test_generic_ext_type_equality():
867867
assert not period_type == period_type3
868868

869869

870+
def test_generic_ext_type_pickling():
871+
# GH-36038
872+
period_type = PeriodType('D')
873+
period_type_pickled = pickle.loads(pickle.dumps(period_type))
874+
assert period_type == period_type_pickled
875+
876+
870877
def test_generic_ext_type_register(registered_period_type):
871878
# test that trying to register other type does not segfault
872879
with pytest.raises(TypeError):

python/pyarrow/types.pxi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,9 @@ cdef class ExtensionType(BaseExtensionType):
14871487
"""
14881488
return NotImplementedError
14891489

1490+
def __reduce__(self):
1491+
return self.__arrow_ext_deserialize__, (self.storage_type, self.__arrow_ext_serialize__())
1492+
14901493
def __arrow_ext_class__(self):
14911494
"""Return an extension array class to be used for building or
14921495
deserializing arrays with this extension type.

0 commit comments

Comments
 (0)