Skip to content

Commit fdf2d3c

Browse files
GH1264 Version 2.0 cleanup
1 parent 69cf85e commit fdf2d3c

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

pandas-stubs/core/indexes/base.pyi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,16 @@ class Index(IndexOpsMixin[S1]):
347347
def __neg__(self) -> Self: ...
348348
def __nonzero__(self) -> None: ...
349349
__bool__ = ...
350-
def union(self, other: list[HashableT] | Index, sort=...) -> Index: ...
351-
def intersection(self, other: list[S1] | Self, sort: bool = ...) -> Self: ...
350+
def union(
351+
self, other: list[HashableT] | Index, sort: bool | None = ...
352+
) -> Index: ...
353+
def intersection(self, other: list[S1] | Self, sort: bool | None = ...) -> Self: ...
352354
def difference(self, other: list | Index, sort: bool | None = None) -> Self: ...
353355
def symmetric_difference(
354-
self, other: list[S1] | Self, result_name: Hashable = ..., sort=...
356+
self,
357+
other: list[S1] | Self,
358+
result_name: Hashable = ...,
359+
sort: bool | None = ...,
355360
) -> Self: ...
356361
def get_loc(
357362
self,
@@ -472,5 +477,6 @@ class Index(IndexOpsMixin[S1]):
472477
| Sequence[float]
473478
),
474479
) -> Self: ...
480+
def infer_objects(self, copy: bool = ...) -> Self: ...
475481

476482
UnknownIndex: TypeAlias = Index[Any]

pandas-stubs/core/indexes/multi.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class MultiIndex(Index):
155155
def equal_levels(self, other): ...
156156
def union(self, other, sort=...): ... # pyrefly: ignore
157157
def intersection( # pyright: ignore[reportIncompatibleMethodOverride]
158-
self, other: list | Self, sort: bool = ...
158+
self, other: list | Self, sort: bool | None = ...
159159
): ...
160160
def difference(self, other, sort=...): ...
161161
def astype(self, dtype: DtypeArg, copy: bool = ...) -> Self: ...

pandas-stubs/core/series.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,13 @@ class TimedeltaSeries(Series[Timedelta]):
23242324
*args: Any,
23252325
**kwargs: Any,
23262326
) -> TimedeltaSeries: ...
2327+
def cumprod(
2328+
self,
2329+
axis: AxisIndex | None = ...,
2330+
skipna: _bool = ...,
2331+
*args: Any,
2332+
**kwargs: Any,
2333+
) -> Never: ...
23272334

23282335
class PeriodSeries(Series[Period]):
23292336
@property

tests/test_indexes.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ def test_difference_none() -> None:
172172
# GH 253
173173
check(assert_type(ind.difference([1]), "pd.Index[int]"), pd.Index)
174174

175+
# check with sort parameter
176+
check(assert_type(ind.difference([1, None], sort=False), "pd.Index[int]"), pd.Index)
177+
check(assert_type(ind.difference([1], sort=True), "pd.Index[int]"), pd.Index)
178+
175179

176180
def test_str_split() -> None:
177181
# GH 194
@@ -312,6 +316,20 @@ def test_range_index_union():
312316
),
313317
pd.Index,
314318
)
319+
check(
320+
assert_type(
321+
pd.RangeIndex(0, 10).union(["a", "b", "c"], sort=True),
322+
Union[pd.Index, "pd.Index[int]", pd.RangeIndex],
323+
),
324+
pd.Index,
325+
)
326+
check(
327+
assert_type(
328+
pd.RangeIndex(0, 10).union(["a", "b", "c"], sort=False),
329+
Union[pd.Index, "pd.Index[int]", pd.RangeIndex],
330+
),
331+
pd.Index,
332+
)
315333

316334

317335
def test_range_index_start_stop_step():
@@ -1361,3 +1379,10 @@ def test_index_dict() -> None:
13611379
),
13621380
pd.TimedeltaIndex,
13631381
)
1382+
1383+
1384+
def test_index_infer_objects() -> None:
1385+
"""Test infer_objects method on Index."""
1386+
df = pd.DataFrame({"A": ["a", 1, 2, 3]})
1387+
idx = df.set_index("A").index[1:]
1388+
check(assert_type(idx.infer_objects(), pd.Index), pd.Index)

tests/test_series.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,3 +3941,8 @@ def test_series_index_type() -> None:
39413941

39423942
if TYPE_CHECKING_INVALID_USAGE:
39433943
t = pd.Series([1, 2], index="ab") # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportArgumentType]
3944+
3945+
3946+
def test_timedelta_index_cumsum() -> None:
3947+
if TYPE_CHECKING_INVALID_USAGE:
3948+
assert_type(pd.Series([pd.Timedelta(0), pd.Timedelta(1)]).cumprod(), Never)

0 commit comments

Comments
 (0)