Skip to content

Commit 59875e3

Browse files
GH1336 Reconcile Series.index and DataFrame.index
1 parent 3033eea commit 59875e3

File tree

5 files changed

+6
-16
lines changed

5 files changed

+6
-16
lines changed

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ from typing import (
1919
import numpy as np
2020
from pandas import (
2121
DatetimeIndex,
22-
Index,
2322
TimedeltaIndex,
2423
)
2524
from pandas.core.series import (
@@ -257,7 +256,7 @@ class Timestamp(datetime, SupportsIndex):
257256
@overload
258257
def __eq__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
259258
@overload
260-
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
259+
def __eq__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
261260
@overload
262261
def __eq__(self, other: np_ndarray[ShapeT, np.datetime64]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
263262
@overload
@@ -267,7 +266,7 @@ class Timestamp(datetime, SupportsIndex):
267266
@overload
268267
def __ne__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
269268
@overload
270-
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
269+
def __ne__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
271270
@overload
272271
def __ne__(self, other: np_ndarray[ShapeT, np.datetime64]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
273272
@overload

pandas-stubs/core/frame.pyi

Lines changed: 2 additions & 5 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
@@ -1763,7 +1760,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
17631760
@property
17641761
# mypy complains if we use Index[Any] instead of UnknownIndex here, even though
17651762
# the latter is aliased to the former ¯\_(ツ)_/¯.
1766-
def index(self) -> UnknownIndex: ...
1763+
def index(self) -> Index: ...
17671764
@index.setter
17681765
def index(self, idx: Index) -> None: ...
17691766
@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: 1 addition & 4 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,9 +1322,6 @@ 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])
1327-
assert (eq_un1 != ne_un1).all()
13281325

13291326
# ==, != (ts on the rhs, use == and != of lhs)
13301327
eq_rhs_dt1 = check(

0 commit comments

Comments
 (0)