2323)
2424from pandas .compat import (
2525 HAS_PYARROW ,
26- pa_version_under11p0 ,
2726 pa_version_under12p1 ,
2827 pa_version_under13p0 ,
2928)
@@ -209,16 +208,6 @@ def floordiv_compat(
209208 from pandas .core .arrays .timedeltas import TimedeltaArray
210209
211210
212- def get_unit_from_pa_dtype (pa_dtype ) -> str :
213- # https://github.com/pandas-dev/pandas/pull/50998#discussion_r1100344804
214- if pa_version_under11p0 :
215- unit = str (pa_dtype ).split ("[" , 1 )[- 1 ][:- 1 ]
216- if unit not in ["s" , "ms" , "us" , "ns" ]:
217- raise ValueError (pa_dtype )
218- return unit
219- return pa_dtype .unit
220-
221-
222211def to_pyarrow_type (
223212 dtype : ArrowDtype | pa .DataType | Dtype | None ,
224213) -> pa .DataType | None :
@@ -1200,10 +1189,6 @@ def factorize(
12001189 null_encoding = "mask" if use_na_sentinel else "encode"
12011190
12021191 data = self ._pa_array
1203- pa_type = data .type
1204- if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1205- # https://github.com/apache/arrow/issues/15226#issuecomment-1376578323
1206- data = data .cast (pa .int64 ())
12071192
12081193 if pa .types .is_dictionary (data .type ):
12091194 if null_encoding == "encode" :
@@ -1228,8 +1213,6 @@ def factorize(
12281213 )
12291214 uniques = type (self )(combined .dictionary )
12301215
1231- if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1232- uniques = cast (ArrowExtensionArray , uniques .astype (self .dtype ))
12331216 return indices , uniques
12341217
12351218 def reshape (self , * args , ** kwargs ):
@@ -1516,19 +1499,7 @@ def unique(self) -> Self:
15161499 -------
15171500 ArrowExtensionArray
15181501 """
1519- pa_type = self ._pa_array .type
1520-
1521- if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1522- # https://github.com/apache/arrow/issues/15226#issuecomment-1376578323
1523- data = self ._pa_array .cast (pa .int64 ())
1524- else :
1525- data = self ._pa_array
1526-
1527- pa_result = pc .unique (data )
1528-
1529- if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1530- pa_result = pa_result .cast (pa_type )
1531-
1502+ pa_result = pc .unique (self ._pa_array )
15321503 return type (self )(pa_result )
15331504
15341505 def value_counts (self , dropna : bool = True ) -> Series :
@@ -1548,18 +1519,12 @@ def value_counts(self, dropna: bool = True) -> Series:
15481519 --------
15491520 Series.value_counts
15501521 """
1551- pa_type = self ._pa_array .type
1552- if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1553- # https://github.com/apache/arrow/issues/15226#issuecomment-1376578323
1554- data = self ._pa_array .cast (pa .int64 ())
1555- else :
1556- data = self ._pa_array
1557-
15581522 from pandas import (
15591523 Index ,
15601524 Series ,
15611525 )
15621526
1527+ data = self ._pa_array
15631528 vc = data .value_counts ()
15641529
15651530 values = vc .field (0 )
@@ -1569,9 +1534,6 @@ def value_counts(self, dropna: bool = True) -> Series:
15691534 values = values .filter (mask )
15701535 counts = counts .filter (mask )
15711536
1572- if pa_version_under11p0 and pa .types .is_duration (pa_type ):
1573- values = values .cast (pa_type )
1574-
15751537 counts = ArrowExtensionArray (counts )
15761538
15771539 index = Index (type (self )(values ))
@@ -1865,8 +1827,7 @@ def pyarrow_meth(data, skip_nulls, min_count=0): # type: ignore[misc]
18651827 if pa .types .is_duration (pa_type ):
18661828 result = result .cast (pa_type )
18671829 elif pa .types .is_time (pa_type ):
1868- unit = get_unit_from_pa_dtype (pa_type )
1869- result = result .cast (pa .duration (unit ))
1830+ result = result .cast (pa .duration (pa_type .unit ))
18701831 elif pa .types .is_date (pa_type ):
18711832 # go with closest available unit, i.e. "s"
18721833 result = result .cast (pa .duration ("s" ))
0 commit comments