diff --git a/pandas-stubs/_libs/tslibs/period.pyi b/pandas-stubs/_libs/tslibs/period.pyi index 603ae742..b658270e 100644 --- a/pandas-stubs/_libs/tslibs/period.pyi +++ b/pandas-stubs/_libs/tslibs/period.pyi @@ -102,7 +102,7 @@ class Period(PeriodMixin): @overload def __eq__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] @overload - def __eq__(self, other: PeriodIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap] + def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap] @overload def __eq__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap] @overload @@ -154,7 +154,7 @@ class Period(PeriodMixin): @overload def __ne__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] @overload - def __ne__(self, other: PeriodIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap] + def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap] @overload def __ne__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap] @overload diff --git a/pandas-stubs/_libs/tslibs/timedeltas.pyi b/pandas-stubs/_libs/tslibs/timedeltas.pyi index 54c0509e..e73b3cc3 100644 --- a/pandas-stubs/_libs/tslibs/timedeltas.pyi +++ b/pandas-stubs/_libs/tslibs/timedeltas.pyi @@ -311,7 +311,7 @@ class Timedelta(timedelta): @overload def __eq__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap] @overload - def __eq__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap] + def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap] @overload def __eq__( # type: ignore[overload-overlap] self, other: np_ndarray[ShapeT, np.timedelta64] @@ -324,7 +324,7 @@ class Timedelta(timedelta): @overload def __ne__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap] @overload - def __ne__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap] + def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap] @overload def __ne__( # type: ignore[overload-overlap] self, other: np_ndarray[ShapeT, np.timedelta64] diff --git a/pandas-stubs/_libs/tslibs/timestamps.pyi b/pandas-stubs/_libs/tslibs/timestamps.pyi index 6146d0b3..ff3a0be5 100644 --- a/pandas-stubs/_libs/tslibs/timestamps.pyi +++ b/pandas-stubs/_libs/tslibs/timestamps.pyi @@ -19,9 +19,9 @@ from typing import ( import numpy as np from pandas import ( DatetimeIndex, - Index, TimedeltaIndex, ) +from pandas.core.indexes.base import Index from pandas.core.series import ( Series, TimedeltaSeries, diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 34ba0547..10bff7b2 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -39,10 +39,7 @@ from pandas.core.arraylike import OpsMixin from pandas.core.generic import NDFrame from pandas.core.groupby.generic import DataFrameGroupBy from pandas.core.indexers import BaseIndexer -from pandas.core.indexes.base import ( - Index, - UnknownIndex, -) +from pandas.core.indexes.base import Index from pandas.core.indexes.category import CategoricalIndex from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.indexes.interval import IntervalIndex @@ -1761,9 +1758,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): @property def iloc(self) -> _iLocIndexerFrame[Self]: ... @property - # mypy complains if we use Index[Any] instead of UnknownIndex here, even though - # the latter is aliased to the former ¯\_(ツ)_/¯. - def index(self) -> UnknownIndex: ... + def index(self) -> Index: ... @index.setter def index(self, idx: Index) -> None: ... @property diff --git a/pandas-stubs/core/indexes/base.pyi b/pandas-stubs/core/indexes/base.pyi index b7bb8a48..b193dccf 100644 --- a/pandas-stubs/core/indexes/base.pyi +++ b/pandas-stubs/core/indexes/base.pyi @@ -15,7 +15,6 @@ from typing import ( ClassVar, Generic, Literal, - TypeAlias, final, overload, type_check_only, @@ -508,8 +507,6 @@ class Index(IndexOpsMixin[S1]): ) -> Self: ... def infer_objects(self, copy: bool = True) -> Self: ... -UnknownIndex: TypeAlias = Index[Any] - @type_check_only class _IndexSubclassBase(Index[S1], Generic[S1, GenericT_co]): @overload diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index f5bea7bf..768e29b7 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -495,7 +495,7 @@ class Series(IndexOpsMixin[S1], NDFrame): self, repeats: int | list[int], axis: AxisIndex | None = 0 ) -> Series[S1]: ... @property - def index(self) -> Index | MultiIndex: ... + def index(self) -> Index: ... @index.setter def index(self, idx: Index) -> None: ... @overload diff --git a/tests/test_scalars.py b/tests/test_scalars.py index 92b29f4b..7feefad3 100644 --- a/tests/test_scalars.py +++ b/tests/test_scalars.py @@ -1287,7 +1287,7 @@ def test_timestamp_cmp_series() -> None: def test_timestamp_cmp_index() -> None: ts = pd.Timestamp(year=2000, month=3, day=24, hour=12, minute=27) dt_idx = pd.DatetimeIndex(["2000-1-1"]) - # DatetimeIndex, but the type checker thinks it is UnknownIndex. + # DatetimeIndex, but the type checker thinks it is Index[Any]. un_idx = pd.DataFrame({"a": [1]}, index=dt_idx).index # >, <= @@ -1322,8 +1322,9 @@ def test_timestamp_cmp_index() -> None: eq_dt1 = check(assert_type(ts == dt_idx, np_1darray[np.bool]), np_1darray[np.bool]) ne_dt1 = check(assert_type(ts != dt_idx, np_1darray[np.bool]), np_1darray[np.bool]) assert (eq_dt1 != ne_dt1).all() - eq_un1 = check(assert_type(ts == un_idx, np_1darray[np.bool]), np_1darray[np.bool]) - ne_un1 = check(assert_type(ts != un_idx, np_1darray[np.bool]), np_1darray[np.bool]) + # there is a mypy bug where ts.__eq__(Index) gets revealed as Any and not np_1darray + eq_un1 = check(assert_type(ts == un_idx, np_1darray[np.bool]), np_1darray[np.bool]) # type: ignore[assert-type] + ne_un1 = check(assert_type(ts != un_idx, np_1darray[np.bool]), np_1darray[np.bool]) # type: ignore[assert-type] assert (eq_un1 != ne_un1).all() # ==, != (ts on the rhs, use == and != of lhs)