Skip to content

Commit 89dec50

Browse files
committed
Reuse types
1 parent 215cc53 commit 89dec50

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

pandas/_libs/ops.pyi

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
from typing import (
2-
Any,
3-
Callable,
42
Iterable,
53
Literal,
6-
TypeAlias,
74
overload,
85
)
96

107
import numpy as np
118

12-
from pandas._typing import npt
13-
14-
_BinOp: TypeAlias = Callable[[Any, Any], Any]
15-
_BoolOp: TypeAlias = Callable[[Any, Any], bool]
9+
from pandas._typing import (
10+
BinOp,
11+
BoolOp,
12+
npt,
13+
)
1614

1715
def scalar_compare(
1816
values: np.ndarray, # object[:]
1917
val: object,
20-
op: _BoolOp, # {operator.eq, operator.ne, ...}
18+
op: BoolOp, # {operator.eq, operator.ne, ...}
2119
) -> npt.NDArray[np.bool_]: ...
2220
def vec_compare(
2321
left: npt.NDArray[np.object_],
2422
right: npt.NDArray[np.object_],
25-
op: _BoolOp, # {operator.eq, operator.ne, ...}
23+
op: BoolOp, # {operator.eq, operator.ne, ...}
2624
) -> npt.NDArray[np.bool_]: ...
2725
def scalar_binop(
2826
values: np.ndarray, # object[:]
2927
val: object,
30-
op: _BinOp, # binary operator
28+
op: BinOp, # binary operator
3129
) -> np.ndarray: ...
3230
def vec_binop(
3331
left: np.ndarray, # object[:]
3432
right: np.ndarray, # object[:]
35-
op: _BinOp, # binary operator
33+
op: BinOp, # binary operator
3634
) -> np.ndarray: ...
3735
@overload
3836
def maybe_convert_bool(

pandas/_typing.py

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Optional,
2424
Protocol,
2525
Type as type_t,
26+
TypeAlias,
2627
TypeVar,
2728
Union,
2829
overload,
@@ -530,3 +531,6 @@ def closed(self) -> bool:
530531

531532
# maintaine the sub-type of any hashable sequence
532533
SequenceT = TypeVar("SequenceT", bound=Sequence[Hashable])
534+
535+
BinOp: TypeAlias = Callable[[Any, Any], Any]
536+
BoolOp: TypeAlias = Callable[[Any, Any], bool]

pandas/core/arrays/period.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import operator
55
from typing import (
66
TYPE_CHECKING,
7-
Any,
87
Callable,
98
Literal,
109
TypeVar,
@@ -80,6 +79,7 @@
8079

8180
from pandas._typing import (
8281
AnyArrayLike,
82+
BinOp,
8383
Dtype,
8484
FillnaOptions,
8585
NpDtype,
@@ -863,9 +863,7 @@ def fillna(
863863
# ------------------------------------------------------------------
864864
# Arithmetic Methods
865865

866-
def _addsub_int_array_or_scalar(
867-
self, other: np.ndarray | int, op: Callable[[Any, Any], Any]
868-
) -> Self:
866+
def _addsub_int_array_or_scalar(self, other: np.ndarray | int, op: BinOp) -> Self:
869867
"""
870868
Add or subtract array of integers.
871869

pandas/core/ops/invalid.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import operator
88
from typing import (
99
TYPE_CHECKING,
10-
Any,
1110
Callable,
1211
NoReturn,
1312
)
@@ -17,6 +16,7 @@
1716
if TYPE_CHECKING:
1817
from pandas._typing import (
1918
ArrayLike,
19+
BoolOp,
2020
Scalar,
2121
npt,
2222
)
@@ -25,7 +25,7 @@
2525
def invalid_comparison(
2626
left: ArrayLike,
2727
right: ArrayLike | Scalar,
28-
op: Callable[[Any, Any], bool], # Can we reuse _BoolOp here?
28+
op: BoolOp,
2929
) -> npt.NDArray[np.bool_]:
3030
"""
3131
If a comparison has mismatched types and is not necessarily meaningful,

0 commit comments

Comments
 (0)