|
23 | 23 | FrozenSet,
|
24 | 24 | Hashable,
|
25 | 25 | Iterable,
|
| 26 | + Iterator, |
26 | 27 | List,
|
27 | 28 | Optional,
|
28 | 29 | Sequence,
|
|
40 | 41 | from pandas._config import get_option
|
41 | 42 |
|
42 | 43 | from pandas._libs import algos as libalgos, lib, properties
|
43 |
| -from pandas._typing import Axes, Axis, Dtype, FilePathOrBuffer, Label, Level, Renamer |
| 44 | +from pandas._typing import ( |
| 45 | + ArrayLike, |
| 46 | + Axes, |
| 47 | + Axis, |
| 48 | + Dtype, |
| 49 | + FilePathOrBuffer, |
| 50 | + Label, |
| 51 | + Level, |
| 52 | + Renamer, |
| 53 | +) |
44 | 54 | from pandas.compat import PY37
|
45 | 55 | from pandas.compat._optional import import_optional_dependency
|
46 | 56 | from pandas.compat.numpy import function as nv
|
@@ -2583,6 +2593,21 @@ def _ixs(self, i: int, axis: int = 0):
|
2583 | 2593 |
|
2584 | 2594 | return result
|
2585 | 2595 |
|
| 2596 | + def _get_column_array(self, i: int) -> ArrayLike: |
| 2597 | + """ |
| 2598 | + Get the values of the i'th column (ndarray or ExtensionArray, as stored |
| 2599 | + in the Block) |
| 2600 | + """ |
| 2601 | + return self._data.iget_values(i) |
| 2602 | + |
| 2603 | + def _iter_column_arrays(self) -> Iterator[ArrayLike]: |
| 2604 | + """ |
| 2605 | + Iterate over the arrays of all columns in order. |
| 2606 | + This returns the values as stored in the Block (ndarray or ExtensionArray). |
| 2607 | + """ |
| 2608 | + for i in range(len(self.columns)): |
| 2609 | + yield self._get_column_array(i) |
| 2610 | + |
2586 | 2611 | def __getitem__(self, key):
|
2587 | 2612 | key = lib.item_from_zerodim(key)
|
2588 | 2613 | key = com.apply_if_callable(key, self)
|
@@ -8046,8 +8071,12 @@ def _reduce(
|
8046 | 8071 |
|
8047 | 8072 | assert filter_type is None or filter_type == "bool", filter_type
|
8048 | 8073 |
|
8049 |
| - dtype_is_dt = self.dtypes.apply( |
8050 |
| - lambda x: is_datetime64_any_dtype(x) or is_period_dtype(x) |
| 8074 | + dtype_is_dt = np.array( |
| 8075 | + [ |
| 8076 | + is_datetime64_any_dtype(values.dtype) or is_period_dtype(values.dtype) |
| 8077 | + for values in self._iter_column_arrays() |
| 8078 | + ], |
| 8079 | + dtype=bool, |
8051 | 8080 | )
|
8052 | 8081 | if numeric_only is None and name in ["mean", "median"] and dtype_is_dt.any():
|
8053 | 8082 | warnings.warn(
|
|
0 commit comments