@@ -1011,12 +1011,11 @@ def factorize(
1011
1011
) -> tuple [np .ndarray , ExtensionArray ]:
1012
1012
null_encoding = "mask" if use_na_sentinel else "encode"
1013
1013
1014
- pa_type = self ._pa_array .type
1015
- if pa .types .is_duration (pa_type ):
1014
+ data = self ._pa_array
1015
+ pa_type = data .type
1016
+ if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1016
1017
# https://github.com/apache/arrow/issues/15226#issuecomment-1376578323
1017
- data = self ._pa_array .cast (pa .int64 ())
1018
- else :
1019
- data = self ._pa_array
1018
+ data = data .cast (pa .int64 ())
1020
1019
1021
1020
if pa .types .is_dictionary (data .type ):
1022
1021
encoded = data
@@ -1034,7 +1033,7 @@ def factorize(
1034
1033
)
1035
1034
uniques = type (self )(encoded .chunk (0 ).dictionary )
1036
1035
1037
- if pa .types .is_duration (pa_type ):
1036
+ if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1038
1037
uniques = cast (ArrowExtensionArray , uniques .astype (self .dtype ))
1039
1038
return indices , uniques
1040
1039
@@ -1273,15 +1272,15 @@ def unique(self) -> Self:
1273
1272
"""
1274
1273
pa_type = self ._pa_array .type
1275
1274
1276
- if pa .types .is_duration (pa_type ):
1275
+ if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1277
1276
# https://github.com/apache/arrow/issues/15226#issuecomment-1376578323
1278
1277
data = self ._pa_array .cast (pa .int64 ())
1279
1278
else :
1280
1279
data = self ._pa_array
1281
1280
1282
1281
pa_result = pc .unique (data )
1283
1282
1284
- if pa .types .is_duration (pa_type ):
1283
+ if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1285
1284
pa_result = pa_result .cast (pa_type )
1286
1285
1287
1286
return type (self )(pa_result )
@@ -1304,7 +1303,7 @@ def value_counts(self, dropna: bool = True) -> Series:
1304
1303
Series.value_counts
1305
1304
"""
1306
1305
pa_type = self ._pa_array .type
1307
- if pa .types .is_duration (pa_type ):
1306
+ if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1308
1307
# https://github.com/apache/arrow/issues/15226#issuecomment-1376578323
1309
1308
data = self ._pa_array .cast (pa .int64 ())
1310
1309
else :
@@ -1324,7 +1323,7 @@ def value_counts(self, dropna: bool = True) -> Series:
1324
1323
values = values .filter (mask )
1325
1324
counts = counts .filter (mask )
1326
1325
1327
- if pa .types .is_duration (pa_type ):
1326
+ if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1328
1327
values = values .cast (pa_type )
1329
1328
1330
1329
counts = ArrowExtensionArray (counts )
0 commit comments