Skip to content

Commit eaf2c25

Browse files
committed
a lot of arithmetic
1 parent 837e14c commit eaf2c25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+651
-230
lines changed

tests/indexes/arithmetic/bool/test_add.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Any
2+
13
import numpy as np
2-
from numpy import typing as npt # noqa: F401
34
import pandas as pd
45
from typing_extensions import assert_type
56

@@ -54,11 +55,23 @@ def test_add_numpy_array() -> None:
5455
# `numpy` typing gives the corresponding `ndarray`s in the static type
5556
# checking, where our `__radd__` cannot override. At runtime, they return
5657
# `Index`es with the correct element type.
57-
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)
59-
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
6058
check(
61-
assert_type(c + left, "npt.NDArray[np.complex128]"),
59+
assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure]
60+
pd.Index,
61+
np.bool_,
62+
)
63+
check(
64+
assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure]
65+
pd.Index,
66+
np.integer,
67+
)
68+
check(
69+
assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure]
70+
pd.Index,
71+
np.floating,
72+
)
73+
check(
74+
assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure]
6275
pd.Index,
6376
np.complexfloating,
6477
)

tests/indexes/arithmetic/bool/test_mul.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any
66

77
import numpy as np
8-
from numpy import typing as npt # noqa: F401
98
import pandas as pd
109
import pytest
1110
from typing_extensions import (
@@ -91,17 +90,29 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None:
9190
# `numpy` typing gives the corresponding `ndarray`s in the static type
9291
# checking, where our `__rmul__` cannot override. At runtime, they return
9392
# `Index` with the correct element type.
94-
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(f * left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
9793
check(
98-
assert_type(c * left, "npt.NDArray[np.complex128]"),
94+
assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure]
95+
pd.Index,
96+
np.bool_,
97+
)
98+
check(
99+
assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure]
100+
pd.Index,
101+
np.integer,
102+
)
103+
check(
104+
assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure]
105+
pd.Index,
106+
np.floating,
107+
)
108+
check(
109+
assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure]
99110
pd.Index,
100111
np.complexfloating,
101112
)
102113
if TYPE_CHECKING_INVALID_USAGE:
103114
assert_type(s * left, Any)
104-
assert_type(d * left, "npt.NDArray[np.timedelta64]")
115+
assert_type(d * left, Any) # pyright: ignore[reportAssertTypeFailure]
105116

106117

107118
def test_mul_pd_index(left: "pd.Index[bool]") -> None:

tests/indexes/arithmetic/bool/test_sub.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from typing import Any
2+
13
import numpy as np
2-
from numpy import typing as npt # noqa: F401
34
import pandas as pd
45
from typing_extensions import (
5-
Never,
66
assert_type,
77
)
88

@@ -56,7 +56,7 @@ def test_sub_numpy_array() -> None:
5656
c = np.array([1.1j, 2.2j, 4.1j], np.complex128)
5757

5858
if TYPE_CHECKING_INVALID_USAGE:
59-
assert_type(left - b, Never)
59+
assert_type(left - b, Any) # pyright: ignore[reportAssertTypeFailure]
6060
check(assert_type(left - i, "pd.Index[int]"), pd.Index, np.integer)
6161
check(assert_type(left - f, "pd.Index[float]"), pd.Index, np.floating)
6262
check(assert_type(left - c, "pd.Index[complex]"), pd.Index, np.complexfloating)
@@ -65,11 +65,19 @@ def test_sub_numpy_array() -> None:
6565
# checking, where our `__rsub__` cannot override. At runtime, they return
6666
# `Index`es with the correct element type.
6767
if TYPE_CHECKING_INVALID_USAGE:
68-
assert_type(b - left, Never)
69-
check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
70-
check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
68+
assert_type(b - left, Any) # pyright: ignore[reportAssertTypeFailure]
69+
check(
70+
assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure]
71+
pd.Index,
72+
np.integer,
73+
)
74+
check(
75+
assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure]
76+
pd.Index,
77+
np.floating,
78+
)
7179
check(
72-
assert_type(c - left, "npt.NDArray[np.complex128]"),
80+
assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure]
7381
pd.Index,
7482
np.complexfloating,
7583
)

tests/indexes/arithmetic/bool/test_truediv.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Any
2+
13
import numpy as np
2-
from numpy import typing as npt # noqa: F401
34
import pandas as pd
45
import pytest
56
from typing_extensions import (
@@ -71,11 +72,19 @@ def test_truediv_numpy_array(left: "pd.Index[bool]") -> None:
7172
# checking, where our `__rtruediv__` cannot override. At runtime, they return
7273
# `Index` with the correct element type.
7374
if TYPE_CHECKING_INVALID_USAGE:
74-
assert_type(b / left, "npt.NDArray[np.float64]")
75-
check(assert_type(i / left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
76-
check(assert_type(f / left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
75+
assert_type(b / left, Any) # pyright: ignore[reportAssertTypeFailure]
76+
check(
77+
assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure]
78+
pd.Index,
79+
np.floating,
80+
)
81+
check(
82+
assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure]
83+
pd.Index,
84+
np.floating,
85+
)
7786
check(
78-
assert_type(c / left, "npt.NDArray[np.complex128]"),
87+
assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure]
7988
pd.Index,
8089
np.complexfloating,
8190
)

tests/indexes/arithmetic/complex/test_add.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Any
2+
13
import numpy as np
2-
from numpy import typing as npt # noqa: F401
34
import pandas as pd
45
from typing_extensions import assert_type
56

@@ -54,13 +55,23 @@ def test_add_numpy_array() -> None:
5455
# `numpy` typing gives the corresponding `ndarray`s in the static type
5556
# checking, where our `__radd__` cannot override. At runtime, they return
5657
# `Index`es with the correct element type.
57-
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)
5958
check(
60-
assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
59+
assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure]
60+
pd.Index,
61+
np.complexfloating,
62+
)
63+
check(
64+
assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure]
65+
pd.Index,
66+
np.complexfloating,
67+
)
68+
check(
69+
assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure]
70+
pd.Index,
71+
np.complexfloating,
6172
)
6273
check(
63-
assert_type(c + left, "npt.NDArray[np.complex128]"),
74+
assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure]
6475
pd.Index,
6576
np.complexfloating,
6677
)

tests/indexes/arithmetic/complex/test_mul.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any
66

77
import numpy as np
8-
from numpy import typing as npt # noqa: F401
98
import pandas as pd
109
import pytest
1110
from typing_extensions import (
@@ -91,19 +90,29 @@ def test_mul_numpy_array(left: "pd.Index[complex]") -> None:
9190
# `numpy` typing gives the corresponding `ndarray`s in the static type
9291
# checking, where our `__rmul__` cannot override. At runtime, they return
9392
# `Index` with the correct element type.
94-
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)
9693
check(
97-
assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
94+
assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure]
95+
pd.Index,
96+
np.complexfloating,
97+
)
98+
check(
99+
assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure]
100+
pd.Index,
101+
np.complexfloating,
102+
)
103+
check(
104+
assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure]
105+
pd.Index,
106+
np.complexfloating,
98107
)
99108
check(
100-
assert_type(c * left, "npt.NDArray[np.complex128]"),
109+
assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure]
101110
pd.Index,
102111
np.complexfloating,
103112
)
104113
if TYPE_CHECKING_INVALID_USAGE:
105114
assert_type(s * left, Any)
106-
assert_type(d * left, "npt.NDArray[np.timedelta64]")
115+
assert_type(d * left, Any) # pyright: ignore[reportAssertTypeFailure]
107116

108117

109118
def test_mul_pd_index(left: "pd.Index[complex]") -> None:

tests/indexes/arithmetic/complex/test_sub.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from typing import NoReturn
1+
from typing import Any
22

33
import numpy as np
4-
from numpy import typing as npt # noqa: F401
54
import pandas as pd
65
from typing_extensions import assert_type
76

@@ -56,13 +55,23 @@ def test_sub_numpy_array() -> None:
5655
# `numpy` typing gives the corresponding `ndarray`s in the static type
5756
# checking, where our `__rsub__` cannot override. At runtime, they return
5857
# `Index`es with the correct element type.
59-
check(assert_type(b - left, NoReturn), pd.Index, np.complexfloating)
60-
check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating)
6158
check(
62-
assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
59+
assert_type(b - left, Any), # pyright: ignore[reportAssertTypeFailure]
60+
pd.Index,
61+
np.complexfloating,
62+
)
63+
check(
64+
assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure]
65+
pd.Index,
66+
np.complexfloating,
67+
)
68+
check(
69+
assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure]
70+
pd.Index,
71+
np.complexfloating,
6372
)
6473
check(
65-
assert_type(c - left, "npt.NDArray[np.complex128]"),
74+
assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure]
6675
pd.Index,
6776
np.complexfloating,
6877
)

tests/indexes/arithmetic/complex/test_truediv.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Any
2+
13
import numpy as np
2-
from numpy import typing as npt # noqa: F401
34
import pandas as pd
45
import pytest
56
from typing_extensions import assert_type
@@ -60,16 +61,22 @@ def test_truediv_numpy_array(left: "pd.Index[complex]") -> None:
6061
# checking, where our `__rtruediv__` cannot override. At runtime, they return
6162
# `Index` with the correct element type.
6263
check(
63-
assert_type(b / left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
64+
assert_type(b / left, Any), # pyright: ignore[reportAssertTypeFailure]
65+
pd.Index,
66+
np.complexfloating,
6467
)
6568
check(
66-
assert_type(i / left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
69+
assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure]
70+
pd.Index,
71+
np.complexfloating,
6772
)
6873
check(
69-
assert_type(f / left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
74+
assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure]
75+
pd.Index,
76+
np.complexfloating,
7077
)
7178
check(
72-
assert_type(c / left, "npt.NDArray[np.complex128]"),
79+
assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure]
7380
pd.Index,
7481
np.complexfloating,
7582
)

tests/indexes/arithmetic/float/test_add.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Any
2+
13
import numpy as np
2-
from numpy import typing as npt # noqa: F401
34
import pandas as pd
45
from typing_extensions import assert_type
56

@@ -54,11 +55,23 @@ def test_add_numpy_array() -> None:
5455
# `numpy` typing gives the corresponding `ndarray`s in the static type
5556
# checking, where our `__radd__` cannot override. At runtime, they return
5657
# `Index`es with the correct element type.
57-
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)
59-
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
6058
check(
61-
assert_type(c + left, "npt.NDArray[np.complex128]"),
59+
assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure]
60+
pd.Index,
61+
np.floating,
62+
)
63+
check(
64+
assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure]
65+
pd.Index,
66+
np.floating,
67+
)
68+
check(
69+
assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure]
70+
pd.Index,
71+
np.floating,
72+
)
73+
check(
74+
assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure]
6275
pd.Index,
6376
np.complexfloating,
6477
)

tests/indexes/arithmetic/float/test_mul.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any
66

77
import numpy as np
8-
from numpy import typing as npt # noqa: F401
98
import pandas as pd
109
import pytest
1110
from typing_extensions import (
@@ -91,18 +90,30 @@ def test_mul_numpy_array(left: "pd.Index[float]") -> None:
9190
# `numpy` typing gives the corresponding `ndarray`s in the static type
9291
# checking, where our `__rmul__` cannot override. At runtime, they return
9392
# `Index` with the correct element type.
94-
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.floating)
95-
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.floating)
96-
check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
9793
check(
98-
assert_type(c * left, "npt.NDArray[np.complex128]"),
94+
assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure]
95+
pd.Index,
96+
np.floating,
97+
)
98+
check(
99+
assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure]
100+
pd.Index,
101+
np.floating,
102+
)
103+
check(
104+
assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure]
105+
pd.Index,
106+
np.floating,
107+
)
108+
check(
109+
assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure]
99110
pd.Index,
100111
np.complexfloating,
101112
)
102113
if TYPE_CHECKING_INVALID_USAGE:
103114
assert_type(s * left, Any)
104115
check(
105-
assert_type(d * left, "npt.NDArray[np.timedelta64]"),
116+
assert_type(d * left, Any), # pyright: ignore[reportAssertTypeFailure]
106117
pd.TimedeltaIndex,
107118
pd.Timedelta,
108119
)

0 commit comments

Comments
 (0)