Skip to content

Commit c95aa39

Browse files
committed
fix: np.ndarray // pd.IndexOpsMixin
1 parent dca5fa2 commit c95aa39

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

tests/indexes/arithmetic/float/test_floordiv.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ def test_floordiv_numpy_array(left: "pd.Index[float]") -> None:
9292
# `numpy` typing gives the corresponding `ndarray`s in the static type
9393
# checking, where our `__rfloordiv__` cannot override. At runtime, they lead to
9494
# errors or pd.Index.
95-
check(b // left, pd.Index, np.floating)
96-
check(i // left, pd.Index, np.floating)
97-
check(f // left, pd.Index, np.floating)
95+
check(assert_type(b // left, "np.typing.NDArray[np.int8]"), pd.Index, np.floating)
96+
check(assert_type(i // left, "np.typing.NDArray[np.int64]"), pd.Index, np.floating)
97+
check(
98+
assert_type(f // left, "np.typing.NDArray[np.float64]"), pd.Index, np.floating
99+
)
98100
if TYPE_CHECKING_INVALID_USAGE:
99101
assert_type(c // left, Any)
100102
assert_type(s // left, Any)

tests/indexes/arithmetic/int/test_floordiv.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,19 @@ def test_floordiv_numpy_array(left: "pd.Index[int]") -> None:
9292
# `numpy` typing gives the corresponding `ndarray`s in the static type
9393
# checking, where our `__rfloordiv__` cannot override. At runtime, they lead to
9494
# errors or pd.Index.
95-
check(b // left, pd.Index, np.integer)
96-
check(i // left, pd.Index, np.integer)
97-
check(f // left, pd.Index, np.floating)
95+
check(assert_type(b // left, "np.typing.NDArray[np.int8]"), pd.Index, np.integer)
96+
check(assert_type(i // left, "np.typing.NDArray[np.int64]"), pd.Index, np.integer)
97+
check(
98+
assert_type(f // left, "np.typing.NDArray[np.float64]"), pd.Index, np.floating
99+
)
98100
if TYPE_CHECKING_INVALID_USAGE:
99101
assert_type(c // left, Any)
100102
assert_type(s // left, Any)
101-
assert_type(d // left, "np.typing.NDArray[np.int64]")
103+
check(
104+
assert_type(d // left, "np.typing.NDArray[np.int64]"),
105+
pd.TimedeltaIndex,
106+
pd.Timedelta,
107+
)
102108

103109

104110
def test_floordiv_pd_index(left: "pd.Index[int]") -> None:

tests/indexes/arithmetic/test_floordiv.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,19 @@ def test_floordiv_numpy_array(left_i: pd.Index) -> None:
9292
# `numpy` typing gives the corresponding `ndarray`s in the static type
9393
# checking, where our `__rfloordiv__` cannot override. At runtime, they lead to
9494
# errors or pd.Index.
95-
check(b // left_i, pd.Index, np.integer)
96-
check(i // left_i, pd.Index, np.integer)
97-
check(f // left_i, pd.Index, np.floating)
95+
check(assert_type(b // left_i, "np.typing.NDArray[np.int8]"), pd.Index, np.integer)
96+
check(assert_type(i // left_i, "np.typing.NDArray[np.int64]"), pd.Index, np.integer)
97+
check(
98+
assert_type(f // left_i, "np.typing.NDArray[np.float64]"), pd.Index, np.floating
99+
)
98100
if TYPE_CHECKING_INVALID_USAGE:
99101
assert_type(c // left_i, Any)
100102
assert_type(s // left_i, Any)
101-
assert_type(d // left_i, Any) # pyright: ignore[reportAssertTypeFailure]
103+
check(
104+
assert_type(d // left_i, "np.typing.NDArray[np.int64]"),
105+
pd.TimedeltaIndex,
106+
pd.Timedelta,
107+
)
102108

103109

104110
def test_floordiv_pd_index(left_i: pd.Index) -> None:

tests/series/arithmetic/int/test_floordiv.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,17 @@ def test_floordiv_numpy_array(left: "pd.Series[int]") -> None:
132132
# `numpy` typing gives the corresponding `ndarray`s in the static type
133133
# checking, where our `__rfloordiv__` cannot override. At runtime, they lead to
134134
# errors or pd.Series.
135-
check(b // left, pd.Series, np.integer)
136-
check(i // left, pd.Series, np.integer)
137-
check(f // left, pd.Series, np.floating)
135+
check(assert_type(b // left, "np.typing.NDArray[np.int8]"), pd.Series, np.integer)
136+
check(assert_type(i // left, "np.typing.NDArray[np.int64]"), pd.Series, np.integer)
137+
check(
138+
assert_type(f // left, "np.typing.NDArray[np.float64]"), pd.Series, np.floating
139+
)
138140
if TYPE_CHECKING_INVALID_USAGE:
139141
assert_type(c // left, Any)
140142
assert_type(s // left, Any)
141-
assert_type(d // left, "np.typing.NDArray[np.int64]")
143+
check(
144+
assert_type(d // left, "np.typing.NDArray[np.int64]"), pd.Series, pd.Timedelta
145+
)
142146

143147
check(assert_type(left.floordiv(b), "pd.Series[int]"), pd.Series, np.integer)
144148
check(assert_type(left.floordiv(i), "pd.Series[int]"), pd.Series, np.integer)

0 commit comments

Comments
 (0)