Skip to content

Commit 90b56d7

Browse files
authored
use np_ndarray_intp, np_ndarray_int64, np_ndarray_float aliases more (#1513)
1 parent 2448b5f commit 90b56d7

36 files changed

+124
-59
lines changed

pandas-stubs/core/groupby/ops.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ from typing import (
55
Generic,
66
)
77

8-
import numpy as np
9-
108
from pandas._typing import (
119
AxisInt,
1210
NDFrameT,
13-
npt,
11+
np_ndarray_intp,
1412
)
1513

1614
class DataSplitter(Generic[NDFrameT]):
1715
data: NDFrameT
18-
labels: npt.NDArray[np.intp]
16+
labels: np_ndarray_intp
1917
ngroups: int
2018
axis: AxisInt
2119
def __iter__(self) -> Iterator[NDFrameT]: ...

pandas-stubs/core/indexes/interval.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ from pandas._typing import (
3131
np_ndarray_bool,
3232
np_ndarray_dt,
3333
np_ndarray_int64,
34+
np_ndarray_intp,
3435
np_ndarray_td,
3536
npt,
3637
)
@@ -41,7 +42,7 @@ _EdgesInt: TypeAlias = (
4142
Sequence[int]
4243
| np_ndarray_int64
4344
| npt.NDArray[np.int32]
44-
| npt.NDArray[np.intp]
45+
| np_ndarray_intp
4546
| pd.Series[int]
4647
| Index[int]
4748
)

tests/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@
6868
np_1darray_td as np_1darray_td,
6969
np_2darray as np_2darray,
7070
np_ndarray as np_ndarray,
71+
np_ndarray_anyint as np_ndarray_anyint,
7172
np_ndarray_bool as np_ndarray_bool,
7273
np_ndarray_dt as np_ndarray_dt,
74+
np_ndarray_float as np_ndarray_float,
7375
np_ndarray_int as np_ndarray_int,
76+
np_ndarray_int64 as np_ndarray_int64,
7477
np_ndarray_intp as np_ndarray_intp,
7578
np_ndarray_num as np_ndarray_num,
7679
np_ndarray_str as np_ndarray_str,
@@ -457,6 +460,8 @@
457460
np_ndarray_int: TypeAlias = npt.NDArray[np.signedinteger]
458461
np_ndarray_intp: TypeAlias = npt.NDArray[np.intp]
459462
np_ndarray_int64: TypeAlias = npt.NDArray[np.int64]
463+
np_ndarray_anyint: TypeAlias = npt.NDArray[np.integer]
464+
np_ndarray_float: TypeAlias = npt.NDArray[np.floating]
460465
np_ndarray_num: TypeAlias = npt.NDArray[np.number]
461466
np_ndarray_str: TypeAlias = npt.NDArray[np.str_]
462467
np_ndarray_td: TypeAlias = npt.NDArray[np.timedelta64]

tests/indexes/arithmetic/bool/test_add.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import pandas as pd
44
from typing_extensions import assert_type
55

6-
from tests import check
6+
from tests import (
7+
check,
8+
np_ndarray_int64,
9+
)
710

811
# left operand
912
left = pd.Index([True, True, False])
@@ -55,7 +58,7 @@ def test_add_numpy_array() -> None:
5558
# checking, where our `__radd__` cannot override. At runtime, they return
5659
# `Index`es with the correct element type.
5760
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.bool_)
58-
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
61+
check(assert_type(i + left, np_ndarray_int64), pd.Index, np.integer)
5962
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
6063
check(
6164
assert_type(c + left, "npt.NDArray[np.complex128]"),

tests/indexes/arithmetic/bool/test_mul.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from tests import (
1717
TYPE_CHECKING_INVALID_USAGE,
1818
check,
19+
np_ndarray_int64,
1920
)
2021

2122

@@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None:
9293
# checking, where our `__rmul__` cannot override. At runtime, they return
9394
# `Index` with the correct element type.
9495
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.bool_)
95-
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
96+
check(assert_type(i * left, np_ndarray_int64), pd.Index, np.integer)
9697
check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
9798
check(
9899
assert_type(c * left, "npt.NDArray[np.complex128]"),

tests/indexes/arithmetic/bool/test_sub.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from tests import (
1010
TYPE_CHECKING_INVALID_USAGE,
1111
check,
12+
np_ndarray_int64,
1213
)
1314

1415
left = pd.Index([True, True, False]) # left operand
@@ -66,7 +67,7 @@ def test_sub_numpy_array() -> None:
6667
# `Index`es with the correct element type.
6768
if TYPE_CHECKING_INVALID_USAGE:
6869
assert_type(b - left, Never)
69-
check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
70+
check(assert_type(i - left, np_ndarray_int64), pd.Index, np.integer)
7071
check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
7172
check(
7273
assert_type(c - left, "npt.NDArray[np.complex128]"),

tests/indexes/arithmetic/complex/test_add.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import pandas as pd
44
from typing_extensions import assert_type
55

6-
from tests import check
6+
from tests import (
7+
check,
8+
np_ndarray_int64,
9+
)
710

811
# left operand
912
left = pd.Index([1j, 2j, 3j])
@@ -55,7 +58,7 @@ def test_add_numpy_array() -> None:
5558
# checking, where our `__radd__` cannot override. At runtime, they return
5659
# `Index`es with the correct element type.
5760
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.complexfloating)
58-
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating)
61+
check(assert_type(i + left, np_ndarray_int64), pd.Index, np.complexfloating)
5962
check(
6063
assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
6164
)

tests/indexes/arithmetic/complex/test_mul.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from tests import (
1717
TYPE_CHECKING_INVALID_USAGE,
1818
check,
19+
np_ndarray_int64,
1920
)
2021

2122

@@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[complex]") -> None:
9293
# checking, where our `__rmul__` cannot override. At runtime, they return
9394
# `Index` with the correct element type.
9495
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.complexfloating)
95-
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating)
96+
check(assert_type(i * left, np_ndarray_int64), pd.Index, np.complexfloating)
9697
check(
9798
assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
9899
)

tests/indexes/arithmetic/complex/test_sub.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import pandas as pd
66
from typing_extensions import assert_type
77

8-
from tests import check
8+
from tests import (
9+
check,
10+
np_ndarray_int64,
11+
)
912

1013
# left operand
1114
left = pd.Index([1j, 2j, 3j])
@@ -57,7 +60,7 @@ def test_sub_numpy_array() -> None:
5760
# checking, where our `__rsub__` cannot override. At runtime, they return
5861
# `Index`es with the correct element type.
5962
check(assert_type(b - left, NoReturn), pd.Index, np.complexfloating)
60-
check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating)
63+
check(assert_type(i - left, np_ndarray_int64), pd.Index, np.complexfloating)
6164
check(
6265
assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
6366
)

tests/indexes/arithmetic/float/test_add.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import pandas as pd
44
from typing_extensions import assert_type
55

6-
from tests import check
6+
from tests import (
7+
check,
8+
np_ndarray_int64,
9+
)
710

811
# left operand
912
left = pd.Index([1.0, 2.0, 3.0])
@@ -55,7 +58,7 @@ def test_add_numpy_array() -> None:
5558
# checking, where our `__radd__` cannot override. At runtime, they return
5659
# `Index`es with the correct element type.
5760
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.floating)
58-
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.floating)
61+
check(assert_type(i + left, np_ndarray_int64), pd.Index, np.floating)
5962
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
6063
check(
6164
assert_type(c + left, "npt.NDArray[np.complex128]"),

0 commit comments

Comments
 (0)