|
24 | 24 | pa_version_under8p0,
|
25 | 25 | pa_version_under9p0,
|
26 | 26 | pa_version_under11p0,
|
| 27 | + pa_version_under13p0, |
27 | 28 | )
|
28 | 29 | from pandas.util._decorators import doc
|
29 | 30 | from pandas.util._validators import validate_fillna_kwargs
|
@@ -1218,7 +1219,7 @@ def to_numpy(
|
1218 | 1219 | else:
|
1219 | 1220 | result = result.to_numpy(dtype=dtype)
|
1220 | 1221 | return result
|
1221 |
| - elif pa.types.is_time(pa_type): |
| 1222 | + elif pa.types.is_time(pa_type) or pa.types.is_date(pa_type): |
1222 | 1223 | # convert to list of python datetime.time objects before
|
1223 | 1224 | # wrapping in ndarray
|
1224 | 1225 | result = np.array(list(self), dtype=dtype)
|
@@ -1416,6 +1417,8 @@ def _reduce_pyarrow(self, name: str, *, skipna: bool = True, **kwargs) -> pa.Sca
|
1416 | 1417 |
|
1417 | 1418 | data_to_reduce = self._pa_array
|
1418 | 1419 |
|
| 1420 | + cast_kwargs = {} if pa_version_under13p0 else {"safe": False} |
| 1421 | + |
1419 | 1422 | if name in ["any", "all"] and (
|
1420 | 1423 | pa.types.is_integer(pa_type)
|
1421 | 1424 | or pa.types.is_floating(pa_type)
|
@@ -1491,9 +1494,15 @@ def pyarrow_meth(data, skip_nulls, **kwargs):
|
1491 | 1494 | if name in ["min", "max", "sum"] and pa.types.is_duration(pa_type):
|
1492 | 1495 | result = result.cast(pa_type)
|
1493 | 1496 | if name in ["median", "mean"] and pa.types.is_temporal(pa_type):
|
| 1497 | + if not pa_version_under13p0: |
| 1498 | + nbits = pa_type.bit_width |
| 1499 | + if nbits == 32: |
| 1500 | + result = result.cast(pa.int32(), **cast_kwargs) |
| 1501 | + else: |
| 1502 | + result = result.cast(pa.int64(), **cast_kwargs) |
1494 | 1503 | result = result.cast(pa_type)
|
1495 | 1504 | if name in ["std", "sem"] and pa.types.is_temporal(pa_type):
|
1496 |
| - result = result.cast(pa.int64()) |
| 1505 | + result = result.cast(pa.int64(), **cast_kwargs) |
1497 | 1506 | if pa.types.is_duration(pa_type):
|
1498 | 1507 | result = result.cast(pa_type)
|
1499 | 1508 | elif pa.types.is_time(pa_type):
|
|
0 commit comments