@@ -1223,9 +1223,9 @@ def _accumulate(
1223
1223
1224
1224
return type (self )(result )
1225
1225
1226
- def _reduce (self , name : str , * , skipna : bool = True , ** kwargs ):
1226
+ def _reduce_pyarrow (self , name : str , * , skipna : bool = True , ** kwargs ) -> pa . Scalar :
1227
1227
"""
1228
- Return a scalar result of performing the reduction operation.
1228
+ Return a pyarrow scalar result of performing the reduction operation.
1229
1229
1230
1230
Parameters
1231
1231
----------
@@ -1241,7 +1241,7 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
1241
1241
1242
1242
Returns
1243
1243
-------
1244
- scalar
1244
+ pyarrow scalar
1245
1245
1246
1246
Raises
1247
1247
------
@@ -1321,7 +1321,7 @@ def pyarrow_meth(data, skip_nulls, **kwargs):
1321
1321
# GH 52679: Use quantile instead of approximate_median; returns array
1322
1322
result = result [0 ]
1323
1323
if pc .is_null (result ).as_py ():
1324
- return self . dtype . na_value
1324
+ return result
1325
1325
1326
1326
if name in ["min" , "max" , "sum" ] and pa .types .is_duration (pa_type ):
1327
1327
result = result .cast (pa_type )
@@ -1341,6 +1341,37 @@ def pyarrow_meth(data, skip_nulls, **kwargs):
1341
1341
# i.e. timestamp
1342
1342
result = result .cast (pa .duration (pa_type .unit ))
1343
1343
1344
+ return result
1345
+
1346
+ def _reduce (self , name : str , * , skipna : bool = True , ** kwargs ):
1347
+ """
1348
+ Return a scalar result of performing the reduction operation.
1349
+
1350
+ Parameters
1351
+ ----------
1352
+ name : str
1353
+ Name of the function, supported values are:
1354
+ { any, all, min, max, sum, mean, median, prod,
1355
+ std, var, sem, kurt, skew }.
1356
+ skipna : bool, default True
1357
+ If True, skip NaN values.
1358
+ **kwargs
1359
+ Additional keyword arguments passed to the reduction function.
1360
+ Currently, `ddof` is the only supported kwarg.
1361
+
1362
+ Returns
1363
+ -------
1364
+ scalar
1365
+
1366
+ Raises
1367
+ ------
1368
+ TypeError : subclass does not define reductions
1369
+ """
1370
+ result = self ._reduce_pyarrow (name , skipna = skipna , ** kwargs )
1371
+
1372
+ if pc .is_null (result ).as_py ():
1373
+ return self .dtype .na_value
1374
+
1344
1375
return result .as_py ()
1345
1376
1346
1377
def __setitem__ (self , key , value ) -> None :
0 commit comments