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
2 changes: 1 addition & 1 deletion pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ TimeNonexistent: TypeAlias = (
DropKeep: TypeAlias = Literal["first", "last", False]
CorrelationMethod: TypeAlias = (
Literal["pearson", "kendall", "spearman"]
| Callable[[np.typing.NDArray[Any], np.typing.NDArray[Any]], float]
| Callable[[npt.NDArray[Any], npt.NDArray[Any]], float]
)
AlignJoin: TypeAlias = Literal["outer", "inner", "left", "right"]
DtypeBackend: TypeAlias = Literal["pyarrow", "numpy_nullable"]
Expand Down
5 changes: 3 additions & 2 deletions pandas-stubs/core/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ from typing import (

from _typeshed import _T_contra
import numpy as np
import numpy.typing as npt
from pandas.core.arraylike import OpsMixin
from pandas.core.arrays import ExtensionArray
from pandas.core.arrays.categorical import Categorical
Expand Down Expand Up @@ -222,7 +223,7 @@ ScalarArrayIndexReal: TypeAlias = (
float
| Sequence[float | NumpyRealScalar]
| NumpyRealScalar
| np.typing.NDArray[NumpyRealScalar]
| npt.NDArray[NumpyRealScalar]
| ExtensionArray
| IndexReal
)
Expand All @@ -235,7 +236,7 @@ ScalarArrayIndexComplex: TypeAlias = (
complex
| Sequence[complex | NumpyComplexScalar]
| NumpyComplexScalar
| np.typing.NDArray[NumpyComplexScalar]
| npt.NDArray[NumpyComplexScalar]
| ExtensionArray
| IndexComplex
)
Expand Down
17 changes: 8 additions & 9 deletions pandas-stubs/core/indexes/accessors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ from typing import (
type_check_only,
)

import numpy as np
from pandas.core.accessor import PandasDelegate
from pandas.core.arrays.base import ExtensionArray
from pandas.core.arrays.categorical import Categorical
Expand Down Expand Up @@ -45,8 +44,8 @@ from pandas._typing import (
TimestampConvention,
TimeUnit,
TimeZones,
np_1darray,
np_1darray_bool,
np_1darray_object,
np_ndarray_bool,
)

Expand Down Expand Up @@ -135,10 +134,10 @@ class _DatetimeObjectOps(
): ...

_DTOtherOpsDateReturnType = TypeVar(
"_DTOtherOpsDateReturnType", bound=Series[date] | np_1darray[np.object_]
"_DTOtherOpsDateReturnType", bound=Series[date] | np_1darray_object
)
_DTOtherOpsTimeReturnType = TypeVar(
"_DTOtherOpsTimeReturnType", bound=Series[time] | np_1darray[np.object_]
"_DTOtherOpsTimeReturnType", bound=Series[time] | np_1darray_object
)

class _DatetimeOtherOps(Generic[_DTOtherOpsDateReturnType, _DTOtherOpsTimeReturnType]):
Expand Down Expand Up @@ -293,7 +292,7 @@ class DatetimeProperties(
_DTToPeriodReturnType,
],
):
def to_pydatetime(self) -> np_1darray[np.object_]: ...
def to_pydatetime(self) -> np_1darray_object: ...
def isocalendar(self) -> DataFrame: ...
@property
def unit(self) -> TimeUnit: ...
Expand All @@ -309,7 +308,7 @@ _TDTotalSecondsReturnType = TypeVar(
class _TimedeltaPropertiesNoRounding(
Generic[_TDNoRoundingMethodReturnType, _TDTotalSecondsReturnType]
):
def to_pytimedelta(self) -> np_1darray[np.object_]: ...
def to_pytimedelta(self) -> np_1darray_object: ...
@property
def components(self) -> DataFrame: ...
@property
Expand Down Expand Up @@ -418,8 +417,8 @@ class DatetimeIndexProperties(
Index[int],
np_1darray_bool,
DatetimeIndex,
np_1darray[np.object_],
np_1darray[np.object_],
np_1darray_object,
np_1darray_object,
BaseOffset,
DatetimeIndex,
Index,
Expand All @@ -431,7 +430,7 @@ class DatetimeIndexProperties(
def is_normalized(self) -> bool: ...
@property
def tzinfo(self) -> _tzinfo | None: ...
def to_pydatetime(self) -> np_1darray[np.object_]: ...
def to_pydatetime(self) -> np_1darray_object: ...
def std(
self, axis: int | None = ..., ddof: int = ..., skipna: bool = ...
) -> Timedelta: ...
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/core/indexes/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ from pandas._typing import (
AxesData,
Dtype,
Frequency,
np_1darray,
np_1darray_intp,
np_1darray_object,
np_ndarray_bool,
)

Expand All @@ -37,7 +37,7 @@ class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexField
name: Hashable | None = None,
) -> Self: ...
@property
def values(self) -> np_1darray[np.object_]: ...
def values(self) -> np_1darray_object: ...
def __add__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: datetime.timedelta
) -> Self: ...
Expand Down
11 changes: 8 additions & 3 deletions tests/indexes/arithmetic/bool/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests._typing import np_ndarray_int64
from tests import (
check,
)
from tests._typing import (
np_ndarray_bool,
np_ndarray_int64,
)

# left operand
left = pd.Index([True, True, False])
Expand Down Expand Up @@ -55,7 +60,7 @@ def test_add_numpy_array() -> None:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# 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(b + left, np_ndarray_bool), pd.Index, np.bool_)
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(
Expand Down
10 changes: 7 additions & 3 deletions tests/indexes/arithmetic/bool/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
TYPE_CHECKING_INVALID_USAGE,
check,
)
from tests._typing import np_ndarray_int64
from tests._typing import (
np_ndarray_bool,
np_ndarray_int64,
np_ndarray_td,
)


@pytest.fixture
Expand Down Expand Up @@ -92,7 +96,7 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# 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(b * left, np_ndarray_bool), pd.Index, np.bool_)
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(
Expand All @@ -102,7 +106,7 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None:
)
if TYPE_CHECKING_INVALID_USAGE:
assert_type(s * left, Any)
assert_type(d * left, "npt.NDArray[np.timedelta64]")
assert_type(d * left, np_ndarray_td)


def test_mul_pd_index(left: "pd.Index[bool]") -> None:
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 @@ -4,7 +4,10 @@
from typing_extensions import assert_type

from tests import check
from tests._typing import np_ndarray_int64
from tests._typing import (
np_ndarray_bool,
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:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# 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(b + left, np_ndarray_bool), 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
10 changes: 7 additions & 3 deletions tests/indexes/arithmetic/complex/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
TYPE_CHECKING_INVALID_USAGE,
check,
)
from tests._typing import np_ndarray_int64
from tests._typing import (
np_ndarray_bool,
np_ndarray_int64,
np_ndarray_td,
)


@pytest.fixture
Expand Down Expand Up @@ -92,7 +96,7 @@ def test_mul_numpy_array(left: "pd.Index[complex]") -> None:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# 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(b * left, np_ndarray_bool), 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 All @@ -104,7 +108,7 @@ def test_mul_numpy_array(left: "pd.Index[complex]") -> None:
)
if TYPE_CHECKING_INVALID_USAGE:
assert_type(s * left, Any)
assert_type(d * left, "npt.NDArray[np.timedelta64]")
assert_type(d * left, np_ndarray_td)


def test_mul_pd_index(left: "pd.Index[complex]") -> None:
Expand Down
11 changes: 8 additions & 3 deletions tests/indexes/arithmetic/float/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests._typing import np_ndarray_int64
from tests import (
check,
)
from tests._typing import (
np_ndarray_bool,
np_ndarray_int64,
)

# left operand
left = pd.Index([1.0, 2.0, 3.0])
Expand Down Expand Up @@ -55,7 +60,7 @@ def test_add_numpy_array() -> None:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# 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(b + left, np_ndarray_bool), 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(
Expand Down
14 changes: 8 additions & 6 deletions tests/indexes/arithmetic/float/test_floordiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any

import numpy as np
import numpy.typing as npt # noqa: F401
import pandas as pd
import pytest
from typing_extensions import (
Expand All @@ -16,6 +17,9 @@
TYPE_CHECKING_INVALID_USAGE,
check,
)
from tests._typing import (
np_ndarray_int64,
)


@pytest.fixture
Expand Down Expand Up @@ -92,16 +96,14 @@ def test_floordiv_numpy_array(left: "pd.Index[float]") -> None:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# checking, where our `__rfloordiv__` cannot override. At runtime, they lead to
# errors or pd.Index.
check(assert_type(b // left, "np.typing.NDArray[np.int8]"), pd.Index, np.floating)
check(assert_type(i // left, "np.typing.NDArray[np.int64]"), pd.Index, np.floating)
check(
assert_type(f // left, "np.typing.NDArray[np.float64]"), pd.Index, np.floating
)
check(assert_type(b // left, "npt.NDArray[np.int8]"), 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)
if TYPE_CHECKING_INVALID_USAGE:
assert_type(c // left, Any)
assert_type(s // left, Any)
check(
assert_type(d // left, "np.typing.NDArray[np.int64]"),
assert_type(d // left, np_ndarray_int64),
pd.TimedeltaIndex,
pd.Timedelta,
)
Expand Down
10 changes: 7 additions & 3 deletions tests/indexes/arithmetic/float/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
TYPE_CHECKING_INVALID_USAGE,
check,
)
from tests._typing import np_ndarray_int64
from tests._typing import (
np_ndarray_bool,
np_ndarray_int64,
np_ndarray_td,
)


@pytest.fixture
Expand Down Expand Up @@ -92,7 +96,7 @@ def test_mul_numpy_array(left: "pd.Index[float]") -> None:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# 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(b * left, np_ndarray_bool), 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(
Expand All @@ -103,7 +107,7 @@ def test_mul_numpy_array(left: "pd.Index[float]") -> None:
if TYPE_CHECKING_INVALID_USAGE:
assert_type(s * left, Any)
check(
assert_type(d * left, "npt.NDArray[np.timedelta64]"),
assert_type(d * left, np_ndarray_td),
pd.TimedeltaIndex,
pd.Timedelta,
)
Expand Down
11 changes: 8 additions & 3 deletions tests/indexes/arithmetic/int/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests._typing import np_ndarray_int64
from tests import (
check,
)
from tests._typing import (
np_ndarray_bool,
np_ndarray_int64,
)

# left operand
left = pd.Index([1, 2, 3])
Expand Down Expand Up @@ -55,7 +60,7 @@ def test_add_numpy_array() -> None:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# 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(b + left, np_ndarray_bool), 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(
Expand Down
14 changes: 8 additions & 6 deletions tests/indexes/arithmetic/int/test_floordiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any

import numpy as np
import numpy.typing as npt # noqa:F401
import pandas as pd
import pytest
from typing_extensions import (
Expand All @@ -16,6 +17,9 @@
TYPE_CHECKING_INVALID_USAGE,
check,
)
from tests._typing import (
np_ndarray_int64,
)


@pytest.fixture
Expand Down Expand Up @@ -92,16 +96,14 @@ def test_floordiv_numpy_array(left: "pd.Index[int]") -> None:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# checking, where our `__rfloordiv__` cannot override. At runtime, they lead to
# errors or pd.Index.
check(assert_type(b // left, "np.typing.NDArray[np.int8]"), pd.Index, np.integer)
check(assert_type(i // left, "np.typing.NDArray[np.int64]"), pd.Index, np.integer)
check(
assert_type(f // left, "np.typing.NDArray[np.float64]"), pd.Index, np.floating
)
check(assert_type(b // left, "npt.NDArray[np.int8]"), 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)
if TYPE_CHECKING_INVALID_USAGE:
assert_type(c // left, Any)
assert_type(s // left, Any)
check(
assert_type(d // left, "np.typing.NDArray[np.int64]"),
assert_type(d // left, np_ndarray_int64),
pd.TimedeltaIndex,
pd.Timedelta,
)
Expand Down
Loading