Skip to content

Commit ba736d9

Browse files
authored
fix: removal of pyarrow.lib.PyExtensionType in pyarrow 21 (#3581)
* only check for PyExtensionType if version is less than 21 * should be less than * fix typo * do a try, except block instead * better comments
1 parent 525acf3 commit ba736d9

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/awkward/_connect/pyarrow/conversions.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,16 @@ def popbuffers(paarray, awkwardarrow_type, storage_type, buffers, generate_bitma
186186
if awkwardarrow_type is not None:
187187
paarray = paarray.storage
188188
### Beginning of the big if-elif-elif chain!
189+
try:
190+
if isinstance(storage_type, pyarrow.lib.PyExtensionType):
191+
raise ValueError(
192+
"Arrow arrays containing pickled Python objects can't be converted into Awkward Arrays"
193+
)
194+
except AttributeError:
195+
# PyExtensionType is deprecated in pyarrow 21.0.0.
196+
pass
189197

190-
if isinstance(storage_type, pyarrow.lib.PyExtensionType):
191-
raise ValueError(
192-
"Arrow arrays containing pickled Python objects can't be converted into Awkward Arrays"
193-
)
194-
195-
elif isinstance(storage_type, pyarrow.lib.ExtensionType):
198+
if isinstance(storage_type, pyarrow.lib.ExtensionType):
196199
# AwkwardArrowType should already be unwrapped; this must be some other ExtensionType.
197200
assert not isinstance(storage_type, AwkwardArrowType)
198201
# In that case, just ignore its logical type and use its storage type.
@@ -495,12 +498,16 @@ def popbuffers(paarray, awkwardarrow_type, storage_type, buffers, generate_bitma
495498
def form_popbuffers(awkwardarrow_type, storage_type):
496499
### Beginning of the big if-elif-elif chain!
497500

498-
if isinstance(storage_type, pyarrow.lib.PyExtensionType):
499-
raise ValueError(
500-
"Arrow arrays containing pickled Python objects can't be converted into Awkward Arrays"
501-
)
501+
try:
502+
if isinstance(storage_type, pyarrow.lib.PyExtensionType):
503+
raise ValueError(
504+
"Arrow arrays containing pickled Python objects can't be converted into Awkward Arrays"
505+
)
506+
except AttributeError:
507+
# PyExtensionType is deprecated in pyarrow 21.0.0.
508+
pass
502509

503-
elif isinstance(storage_type, pyarrow.lib.ExtensionType):
510+
if isinstance(storage_type, pyarrow.lib.ExtensionType):
504511
# AwkwardArrowType should already be unwrapped; this must be some other ExtensionType.
505512
assert not isinstance(storage_type, AwkwardArrowType)
506513
# In that case, just ignore its logical type and use its storage type.

0 commit comments

Comments
 (0)