@@ -2136,91 +2136,7 @@ cdef class OpaqueType(BaseExtensionType):
2136
2136
return OpaqueScalar
2137
2137
2138
2138
2139
- _py_extension_type_auto_load = False
2140
-
2141
-
2142
- cdef class PyExtensionType(ExtensionType):
2143
- """
2144
- Concrete base class for Python-defined extension types based on pickle
2145
- for (de)serialization.
2146
-
2147
- .. warning::
2148
- This class is deprecated and its deserialization is disabled by default.
2149
- :class:`ExtensionType` is recommended instead.
2150
-
2151
- Parameters
2152
- ----------
2153
- storage_type : DataType
2154
- The storage type for which the extension is built.
2155
- """
2156
-
2157
- def __cinit__ (self ):
2158
- if type (self ) is PyExtensionType:
2159
- raise TypeError (" Can only instantiate subclasses of "
2160
- " PyExtensionType" )
2161
-
2162
- def __init__ (self , DataType storage_type ):
2163
- warnings.warn(
2164
- " pyarrow.PyExtensionType is deprecated "
2165
- " and will refuse deserialization by default. "
2166
- " Instead, please derive from pyarrow.ExtensionType and implement "
2167
- " your own serialization mechanism." ,
2168
- FutureWarning )
2169
- ExtensionType.__init__ (self , storage_type, " arrow.py_extension_type" )
2170
-
2171
- def __reduce__ (self ):
2172
- raise NotImplementedError (" Please implement {0}.__reduce__"
2173
- .format(type (self ).__name__))
2174
-
2175
- def __arrow_ext_serialize__ (self ):
2176
- return pickle.dumps(self )
2177
-
2178
- @classmethod
2179
- def __arrow_ext_deserialize__ (cls , storage_type , serialized ):
2180
- if not _py_extension_type_auto_load:
2181
- warnings.warn(
2182
- " pickle-based deserialization of pyarrow.PyExtensionType subclasses "
2183
- " is disabled by default; if you only ingest "
2184
- " trusted data files, you may re-enable this using "
2185
- " `pyarrow.PyExtensionType.set_auto_load(True)`.\n "
2186
- " In the future, Python-defined extension subclasses should "
2187
- " derive from pyarrow.ExtensionType (not pyarrow.PyExtensionType) "
2188
- " and implement their own serialization mechanism.\n " ,
2189
- RuntimeWarning )
2190
- return UnknownExtensionType(storage_type, serialized)
2191
- try :
2192
- ty = pickle.loads(serialized)
2193
- except Exception :
2194
- # For some reason, it's impossible to deserialize the
2195
- # ExtensionType instance. Perhaps the serialized data is
2196
- # corrupt, or more likely the type is being deserialized
2197
- # in an environment where the original Python class or module
2198
- # is not available. Fall back on a generic BaseExtensionType.
2199
- return UnknownExtensionType(storage_type, serialized)
2200
-
2201
- if ty.storage_type != storage_type:
2202
- raise TypeError (" Expected storage type {0} but got {1}"
2203
- .format(ty.storage_type, storage_type))
2204
- return ty
2205
-
2206
- # XXX Cython marks extension types as immutable, so cannot expose this
2207
- # as a writable class attribute.
2208
- @classmethod
2209
- def set_auto_load (cls , value ):
2210
- """
2211
- Enable or disable auto-loading of serialized PyExtensionType instances.
2212
-
2213
- Parameters
2214
- ----------
2215
- value : bool
2216
- Whether to enable auto-loading.
2217
- """
2218
- global _py_extension_type_auto_load
2219
- assert isinstance (value, bool )
2220
- _py_extension_type_auto_load = value
2221
-
2222
-
2223
- cdef class UnknownExtensionType(PyExtensionType):
2139
+ cdef class UnknownExtensionType(ExtensionType):
2224
2140
"""
2225
2141
A concrete class for Python-defined extension types that refer to
2226
2142
an unknown Python implementation.
@@ -2238,11 +2154,15 @@ cdef class UnknownExtensionType(PyExtensionType):
2238
2154
2239
2155
def __init__ (self , DataType storage_type , serialized ):
2240
2156
self .serialized = serialized
2241
- PyExtensionType .__init__ (self , storage_type )
2157
+ super () .__init__(storage_type, " pyarrow.unknown " )
2242
2158
2243
2159
def __arrow_ext_serialize__ (self ):
2244
2160
return self .serialized
2245
2161
2162
+ @classmethod
2163
+ def __arrow_ext_deserialize__ (cls , storage_type , serialized ):
2164
+ return UnknownExtensionType()
2165
+
2246
2166
2247
2167
_python_extension_types_registry = []
2248
2168
@@ -6094,39 +6014,6 @@ cdef class _ExtensionRegistryNanny(_Weakrefable):
6094
6014
_registry_nanny = _ExtensionRegistryNanny()
6095
6015
6096
6016
6097
- def _register_py_extension_type ():
6098
- cdef:
6099
- DataType storage_type
6100
- shared_ptr[CExtensionType] cpy_ext_type
6101
- c_string c_extension_name = tobytes(" arrow.py_extension_type" )
6102
-
6103
- # Make a dummy C++ ExtensionType
6104
- storage_type = null()
6105
- check_status(CPyExtensionType.FromClass(
6106
- storage_type.sp_type, c_extension_name, PyExtensionType,
6107
- & cpy_ext_type))
6108
- check_status(
6109
- RegisterPyExtensionType(< shared_ptr[CDataType]> cpy_ext_type))
6110
-
6111
-
6112
- def _unregister_py_extension_types ():
6113
- # This needs to be done explicitly before the Python interpreter is
6114
- # finalized. If the C++ type is destroyed later in the process
6115
- # teardown stage, it will invoke CPython APIs such as Py_DECREF
6116
- # with a destroyed interpreter.
6117
- unregister_extension_type(" arrow.py_extension_type" )
6118
- for ext_type in _python_extension_types_registry:
6119
- try :
6120
- unregister_extension_type(ext_type.extension_name)
6121
- except KeyError :
6122
- pass
6123
- _registry_nanny.release_registry()
6124
-
6125
-
6126
- _register_py_extension_type()
6127
- atexit.register(_unregister_py_extension_types)
6128
-
6129
-
6130
6017
#
6131
6018
# PyCapsule export utilities
6132
6019
#
0 commit comments