|
2 | 2 | """
|
3 | 3 |
|
4 | 4 | from functools import partial, wraps
|
| 5 | +from typing import Dict, Optional, Sequence, Tuple, Type, Union |
5 | 6 | import warnings
|
6 | 7 |
|
7 | 8 | import numpy as np
|
8 | 9 |
|
| 10 | +from pandas._typing import FrameOrSeries |
9 | 11 | from pandas.errors import PerformanceWarning
|
10 | 12 |
|
11 | 13 | from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
|
|
15 | 17 | from pandas.core.computation.common import result_type_many
|
16 | 18 |
|
17 | 19 |
|
18 |
| -def _align_core_single_unary_op(term): |
| 20 | +def _align_core_single_unary_op( |
| 21 | + term, |
| 22 | +) -> Tuple[Union[partial, Type[FrameOrSeries]], Optional[Dict[str, int]]]: |
| 23 | + |
| 24 | + typ: Union[partial, Type[FrameOrSeries]] |
| 25 | + axes: Optional[Dict[str, int]] = None |
| 26 | + |
19 | 27 | if isinstance(term.value, np.ndarray):
|
20 | 28 | typ = partial(np.asanyarray, dtype=term.value.dtype)
|
21 | 29 | else:
|
22 | 30 | typ = type(term.value)
|
23 |
| - ret = (typ,) |
| 31 | + if hasattr(term.value, "axes"): |
| 32 | + axes = _zip_axes_from_type(typ, term.value.axes) |
24 | 33 |
|
25 |
| - if not hasattr(term.value, "axes"): |
26 |
| - ret += (None,) |
27 |
| - else: |
28 |
| - ret += (_zip_axes_from_type(typ, term.value.axes),) |
29 |
| - return ret |
| 34 | + return typ, axes |
30 | 35 |
|
31 | 36 |
|
32 |
| -def _zip_axes_from_type(typ, new_axes): |
33 |
| - axes = {ax_name: new_axes[ax_ind] for ax_ind, ax_name in typ._AXIS_NAMES.items()} |
| 37 | +def _zip_axes_from_type( |
| 38 | + typ: Type[FrameOrSeries], new_axes: Sequence[int] |
| 39 | +) -> Dict[str, int]: |
| 40 | + axes = {name: new_axes[i] for i, name in typ._AXIS_NAMES.items()} |
34 | 41 | return axes
|
35 | 42 |
|
36 | 43 |
|
|
0 commit comments