Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pandas-stubs/core/groupby/ops.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ from typing import (
Generic,
)

import numpy as np

from pandas._typing import (
AxisInt,
NDFrameT,
npt,
np_ndarray_intp,
)

class DataSplitter(Generic[NDFrameT]):
data: NDFrameT
labels: npt.NDArray[np.intp]
labels: np_ndarray_intp
ngroups: int
axis: AxisInt
def __iter__(self) -> Iterator[NDFrameT]: ...
3 changes: 2 additions & 1 deletion pandas-stubs/core/indexes/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ from pandas._typing import (
np_ndarray_bool,
np_ndarray_dt,
np_ndarray_int64,
np_ndarray_intp,
np_ndarray_td,
npt,
)
Expand All @@ -41,7 +42,7 @@ _EdgesInt: TypeAlias = (
Sequence[int]
| np_ndarray_int64
| npt.NDArray[np.int32]
| npt.NDArray[np.intp]
| np_ndarray_intp
| pd.Series[int]
| Index[int]
)
Expand Down
5 changes: 5 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@
np_1darray_td as np_1darray_td,
np_2darray as np_2darray,
np_ndarray as np_ndarray,
np_ndarray_anyint as np_ndarray_anyint,
np_ndarray_bool as np_ndarray_bool,
np_ndarray_dt as np_ndarray_dt,
np_ndarray_float as np_ndarray_float,
np_ndarray_int as np_ndarray_int,
np_ndarray_int64 as np_ndarray_int64,
np_ndarray_intp as np_ndarray_intp,
np_ndarray_num as np_ndarray_num,
np_ndarray_str as np_ndarray_str,
Expand Down Expand Up @@ -457,6 +460,8 @@
np_ndarray_int: TypeAlias = npt.NDArray[np.signedinteger]
np_ndarray_intp: TypeAlias = npt.NDArray[np.intp]
np_ndarray_int64: TypeAlias = npt.NDArray[np.int64]
np_ndarray_anyint: TypeAlias = npt.NDArray[np.integer]
np_ndarray_float: TypeAlias = npt.NDArray[np.floating]
np_ndarray_num: TypeAlias = npt.NDArray[np.number]
np_ndarray_str: TypeAlias = npt.NDArray[np.str_]
np_ndarray_td: TypeAlias = npt.NDArray[np.timedelta64]
Expand Down
7 changes: 5 additions & 2 deletions tests/indexes/arithmetic/bool/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests import (
check,
np_ndarray_int64,
)

# left operand
left = pd.Index([True, True, False])
Expand Down Expand Up @@ -55,7 +58,7 @@ def test_add_numpy_array() -> None:
# checking, where our `__radd__` cannot override. At runtime, they return
# `Index`es with the correct element type.
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.bool_)
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
check(assert_type(i + left, np_ndarray_int64), pd.Index, np.integer)
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
check(
assert_type(c + left, "npt.NDArray[np.complex128]"),
Expand Down
3 changes: 2 additions & 1 deletion tests/indexes/arithmetic/bool/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
np_ndarray_int64,
)


Expand Down Expand Up @@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None:
# checking, where our `__rmul__` cannot override. At runtime, they return
# `Index` with the correct element type.
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.bool_)
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
check(assert_type(i * left, np_ndarray_int64), pd.Index, np.integer)
check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
check(
assert_type(c * left, "npt.NDArray[np.complex128]"),
Expand Down
3 changes: 2 additions & 1 deletion tests/indexes/arithmetic/bool/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
np_ndarray_int64,
)

left = pd.Index([True, True, False]) # left operand
Expand Down Expand Up @@ -66,7 +67,7 @@ def test_sub_numpy_array() -> None:
# `Index`es with the correct element type.
if TYPE_CHECKING_INVALID_USAGE:
assert_type(b - left, Never)
check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
check(assert_type(i - left, np_ndarray_int64), pd.Index, np.integer)
check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
check(
assert_type(c - left, "npt.NDArray[np.complex128]"),
Expand Down
7 changes: 5 additions & 2 deletions tests/indexes/arithmetic/complex/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests import (
check,
np_ndarray_int64,
)

# left operand
left = pd.Index([1j, 2j, 3j])
Expand Down Expand Up @@ -55,7 +58,7 @@ def test_add_numpy_array() -> None:
# checking, where our `__radd__` cannot override. At runtime, they return
# `Index`es with the correct element type.
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.complexfloating)
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating)
check(assert_type(i + left, np_ndarray_int64), pd.Index, np.complexfloating)
check(
assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
)
Expand Down
3 changes: 2 additions & 1 deletion tests/indexes/arithmetic/complex/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
np_ndarray_int64,
)


Expand Down Expand Up @@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[complex]") -> None:
# checking, where our `__rmul__` cannot override. At runtime, they return
# `Index` with the correct element type.
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.complexfloating)
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating)
check(assert_type(i * left, np_ndarray_int64), pd.Index, np.complexfloating)
check(
assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
)
Expand Down
7 changes: 5 additions & 2 deletions tests/indexes/arithmetic/complex/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests import (
check,
np_ndarray_int64,
)

# left operand
left = pd.Index([1j, 2j, 3j])
Expand Down Expand Up @@ -57,7 +60,7 @@ def test_sub_numpy_array() -> None:
# checking, where our `__rsub__` cannot override. At runtime, they return
# `Index`es with the correct element type.
check(assert_type(b - left, NoReturn), pd.Index, np.complexfloating)
check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating)
check(assert_type(i - left, np_ndarray_int64), pd.Index, np.complexfloating)
check(
assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating
)
Expand Down
7 changes: 5 additions & 2 deletions tests/indexes/arithmetic/float/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests import (
check,
np_ndarray_int64,
)

# left operand
left = pd.Index([1.0, 2.0, 3.0])
Expand Down Expand Up @@ -55,7 +58,7 @@ def test_add_numpy_array() -> None:
# checking, where our `__radd__` cannot override. At runtime, they return
# `Index`es with the correct element type.
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.floating)
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.floating)
check(assert_type(i + left, np_ndarray_int64), pd.Index, np.floating)
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
check(
assert_type(c + left, "npt.NDArray[np.complex128]"),
Expand Down
3 changes: 2 additions & 1 deletion tests/indexes/arithmetic/float/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
np_ndarray_int64,
)


Expand Down Expand Up @@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[float]") -> None:
# checking, where our `__rmul__` cannot override. At runtime, they return
# `Index` with the correct element type.
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.floating)
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.floating)
check(assert_type(i * left, np_ndarray_int64), pd.Index, np.floating)
check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
check(
assert_type(c * left, "npt.NDArray[np.complex128]"),
Expand Down
7 changes: 5 additions & 2 deletions tests/indexes/arithmetic/float/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests import (
check,
np_ndarray_int64,
)

# left operand
left = pd.Index([1.0, 2.0, 3.0])
Expand Down Expand Up @@ -57,7 +60,7 @@ def test_sub_numpy_array() -> None:
# checking, where our `__rsub__` cannot override. At runtime, they return
# `Index`es with the correct element type.
check(assert_type(b - left, NoReturn), pd.Index, np.floating)
check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.floating)
check(assert_type(i - left, np_ndarray_int64), pd.Index, np.floating)
check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
check(
assert_type(c - left, "npt.NDArray[np.complex128]"),
Expand Down
7 changes: 5 additions & 2 deletions tests/indexes/arithmetic/int/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests import (
check,
np_ndarray_int64,
)

# left operand
left = pd.Index([1, 2, 3])
Expand Down Expand Up @@ -55,7 +58,7 @@ def test_add_numpy_array() -> None:
# checking, where our `__radd__` cannot override. At runtime, they return
# `Index`es with the correct element type.
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.integer)
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
check(assert_type(i + left, np_ndarray_int64), pd.Index, np.integer)
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
check(
assert_type(c + left, "npt.NDArray[np.complex128]"),
Expand Down
3 changes: 2 additions & 1 deletion tests/indexes/arithmetic/int/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
np_ndarray_int64,
)


Expand Down Expand Up @@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[int]") -> None:
# checking, where our `__rmul__` cannot override. At runtime, they return
# `Index` with the correct element type.
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.integer)
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
check(assert_type(i * left, np_ndarray_int64), pd.Index, np.integer)
check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
check(
assert_type(c * left, "npt.NDArray[np.complex128]"),
Expand Down
7 changes: 5 additions & 2 deletions tests/indexes/arithmetic/int/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests import (
check,
np_ndarray_int64,
)

# left operand
left = pd.Index([1, 2, 3])
Expand Down Expand Up @@ -57,7 +60,7 @@ def test_sub_numpy_array() -> None:
# checking, where our `__rsub__` cannot override. At runtime, they return
# `Index`es with the correct element type.
check(assert_type(b - left, NoReturn), pd.Index, np.integer)
check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
check(assert_type(i - left, np_ndarray_int64), pd.Index, np.integer)
check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating)
check(
assert_type(c - left, "npt.NDArray[np.complex128]"),
Expand Down
3 changes: 2 additions & 1 deletion tests/indexes/arithmetic/str/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
np_ndarray_int64,
)

left = pd.Index(["1", "23", "456"]) # left operand
Expand Down Expand Up @@ -61,7 +62,7 @@ def test_add_numpy_array() -> None:
# checking, where our `__radd__` cannot override. At runtime, they return
# `Index`es.
if TYPE_CHECKING_INVALID_USAGE:
assert_type(i + left, "npt.NDArray[np.int64]")
assert_type(i + left, np_ndarray_int64)
if sys.version_info >= (3, 11):
# `numpy` typing gives `npt.NDArray[np.int64]` in the static type
# checking, where our `__radd__` cannot override. At runtime, they return
Expand Down
3 changes: 2 additions & 1 deletion tests/indexes/arithmetic/str/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
np_ndarray_int64,
)


Expand Down Expand Up @@ -98,7 +99,7 @@ def test_mul_numpy_array(left: "pd.Index[str]") -> None:
# `Index` with the correct element type.
if TYPE_CHECKING_INVALID_USAGE:
assert_type(b * left, "npt.NDArray[np.bool_]")
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, str)
check(assert_type(i * left, np_ndarray_int64), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
assert_type(f * left, "npt.NDArray[np.float64]")
assert_type(c * left, "npt.NDArray[np.complex128]")
Expand Down
5 changes: 3 additions & 2 deletions tests/indexes/arithmetic/timedeltaindex/test_floordiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
np_ndarray_int64,
)


Expand Down Expand Up @@ -95,11 +96,11 @@ def test_floordiv_numpy_array(left: pd.TimedeltaIndex) -> None:
# errors or pd.Series.
if TYPE_CHECKING_INVALID_USAGE:
assert_type(b // left, "npt.NDArray[np.int8]")
assert_type(i // left, "npt.NDArray[np.int64]")
assert_type(i // left, np_ndarray_int64)
assert_type(f // left, "npt.NDArray[np.float64]")
assert_type(c // left, Any)
assert_type(s // left, Any)
check(assert_type(d // left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
check(assert_type(d // left, np_ndarray_int64), pd.Index, np.integer)


def test_floordiv_pd_scalar(left: pd.TimedeltaIndex) -> None:
Expand Down
5 changes: 2 additions & 3 deletions tests/indexes/arithmetic/timedeltaindex/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
np_ndarray_int64,
)


Expand Down Expand Up @@ -78,9 +79,7 @@ def test_mul_numpy_array(left: pd.TimedeltaIndex) -> None:
if TYPE_CHECKING_INVALID_USAGE:
# We made it Never, but numpy takes over
assert_type(b * left, "npt.NDArray[np.bool_]")
check(
assert_type(i * left, "npt.NDArray[np.int64]"), pd.TimedeltaIndex, pd.Timedelta
)
check(assert_type(i * left, np_ndarray_int64), pd.TimedeltaIndex, pd.Timedelta)
check(
assert_type(f * left, "npt.NDArray[np.float64]"),
pd.TimedeltaIndex,
Expand Down
Loading