Skip to content

Commit d1f82f7

Browse files
simonjayhawkinsTomAugspurger
authored andcommitted
TYP: check_untyped_defs pandas.core.computation.align (#30550)
1 parent 392c7b8 commit d1f82f7

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

pandas/core/computation/align.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
"""
33

44
from functools import partial, wraps
5+
from typing import Dict, Optional, Sequence, Tuple, Type, Union
56
import warnings
67

78
import numpy as np
89

10+
from pandas._typing import FrameOrSeries
911
from pandas.errors import PerformanceWarning
1012

1113
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
@@ -15,22 +17,27 @@
1517
from pandas.core.computation.common import result_type_many
1618

1719

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+
1927
if isinstance(term.value, np.ndarray):
2028
typ = partial(np.asanyarray, dtype=term.value.dtype)
2129
else:
2230
typ = type(term.value)
23-
ret = (typ,)
31+
if hasattr(term.value, "axes"):
32+
axes = _zip_axes_from_type(typ, term.value.axes)
2433

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
3035

3136

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()}
3441
return axes
3542

3643

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ check_untyped_defs=False
163163
[mypy-pandas.core.base]
164164
check_untyped_defs=False
165165

166-
[mypy-pandas.core.computation.align]
167-
check_untyped_defs=False
168-
169166
[mypy-pandas.core.computation.expr]
170167
check_untyped_defs=False
171168

0 commit comments

Comments
 (0)