Skip to content

Commit d20612e

Browse files
GH1336 Reconcile Series.index and DataFrame.index (#1349)
* GH1336 Reconcile Series.index and DataFrame.index * GH1336 Remove comment * GH1336 PR Feedback * GH1336 PR Feedback
1 parent 3033eea commit d20612e

File tree

7 files changed

+12
-19
lines changed

7 files changed

+12
-19
lines changed

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Period(PeriodMixin):
102102
@overload
103103
def __eq__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
104104
@overload
105-
def __eq__(self, other: PeriodIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
105+
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
106106
@overload
107107
def __eq__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
108108
@overload
@@ -154,7 +154,7 @@ class Period(PeriodMixin):
154154
@overload
155155
def __ne__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
156156
@overload
157-
def __ne__(self, other: PeriodIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
157+
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
158158
@overload
159159
def __ne__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
160160
@overload

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class Timedelta(timedelta):
311311
@overload
312312
def __eq__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
313313
@overload
314-
def __eq__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
314+
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
315315
@overload
316316
def __eq__( # type: ignore[overload-overlap]
317317
self, other: np_ndarray[ShapeT, np.timedelta64]
@@ -324,7 +324,7 @@ class Timedelta(timedelta):
324324
@overload
325325
def __ne__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
326326
@overload
327-
def __ne__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
327+
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
328328
@overload
329329
def __ne__( # type: ignore[overload-overlap]
330330
self, other: np_ndarray[ShapeT, np.timedelta64]

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ from typing import (
1919
import numpy as np
2020
from pandas import (
2121
DatetimeIndex,
22-
Index,
2322
TimedeltaIndex,
2423
)
24+
from pandas.core.indexes.base import Index
2525
from pandas.core.series import (
2626
Series,
2727
TimedeltaSeries,

pandas-stubs/core/frame.pyi

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ from pandas.core.arraylike import OpsMixin
3939
from pandas.core.generic import NDFrame
4040
from pandas.core.groupby.generic import DataFrameGroupBy
4141
from pandas.core.indexers import BaseIndexer
42-
from pandas.core.indexes.base import (
43-
Index,
44-
UnknownIndex,
45-
)
42+
from pandas.core.indexes.base import Index
4643
from pandas.core.indexes.category import CategoricalIndex
4744
from pandas.core.indexes.datetimes import DatetimeIndex
4845
from pandas.core.indexes.interval import IntervalIndex
@@ -1761,9 +1758,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
17611758
@property
17621759
def iloc(self) -> _iLocIndexerFrame[Self]: ...
17631760
@property
1764-
# mypy complains if we use Index[Any] instead of UnknownIndex here, even though
1765-
# the latter is aliased to the former ¯\_(ツ)_/¯.
1766-
def index(self) -> UnknownIndex: ...
1761+
def index(self) -> Index: ...
17671762
@index.setter
17681763
def index(self, idx: Index) -> None: ...
17691764
@property

pandas-stubs/core/indexes/base.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ from typing import (
1515
ClassVar,
1616
Generic,
1717
Literal,
18-
TypeAlias,
1918
final,
2019
overload,
2120
type_check_only,
@@ -508,8 +507,6 @@ class Index(IndexOpsMixin[S1]):
508507
) -> Self: ...
509508
def infer_objects(self, copy: bool = True) -> Self: ...
510509

511-
UnknownIndex: TypeAlias = Index[Any]
512-
513510
@type_check_only
514511
class _IndexSubclassBase(Index[S1], Generic[S1, GenericT_co]):
515512
@overload

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
495495
self, repeats: int | list[int], axis: AxisIndex | None = 0
496496
) -> Series[S1]: ...
497497
@property
498-
def index(self) -> Index | MultiIndex: ...
498+
def index(self) -> Index: ...
499499
@index.setter
500500
def index(self, idx: Index) -> None: ...
501501
@overload

tests/test_scalars.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ def test_timestamp_cmp_series() -> None:
12871287
def test_timestamp_cmp_index() -> None:
12881288
ts = pd.Timestamp(year=2000, month=3, day=24, hour=12, minute=27)
12891289
dt_idx = pd.DatetimeIndex(["2000-1-1"])
1290-
# DatetimeIndex, but the type checker thinks it is UnknownIndex.
1290+
# DatetimeIndex, but the type checker thinks it is Index[Any].
12911291
un_idx = pd.DataFrame({"a": [1]}, index=dt_idx).index
12921292

12931293
# >, <=
@@ -1322,8 +1322,9 @@ def test_timestamp_cmp_index() -> None:
13221322
eq_dt1 = check(assert_type(ts == dt_idx, np_1darray[np.bool]), np_1darray[np.bool])
13231323
ne_dt1 = check(assert_type(ts != dt_idx, np_1darray[np.bool]), np_1darray[np.bool])
13241324
assert (eq_dt1 != ne_dt1).all()
1325-
eq_un1 = check(assert_type(ts == un_idx, np_1darray[np.bool]), np_1darray[np.bool])
1326-
ne_un1 = check(assert_type(ts != un_idx, np_1darray[np.bool]), np_1darray[np.bool])
1325+
# there is a mypy bug where ts.__eq__(Index) gets revealed as Any and not np_1darray
1326+
eq_un1 = check(assert_type(ts == un_idx, np_1darray[np.bool]), np_1darray[np.bool]) # type: ignore[assert-type]
1327+
ne_un1 = check(assert_type(ts != un_idx, np_1darray[np.bool]), np_1darray[np.bool]) # type: ignore[assert-type]
13271328
assert (eq_un1 != ne_un1).all()
13281329

13291330
# ==, != (ts on the rhs, use == and != of lhs)

0 commit comments

Comments
 (0)