Skip to content

Commit 4b42588

Browse files
authored
type datetimeindex max/min reductions (#1134)
1 parent f7a1b83 commit 4b42588

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

pandas-stubs/core/indexes/datetimelike.pyi

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import numpy as np
12
from pandas.core.indexes.extension import ExtensionIndex
23
from pandas.core.indexes.timedeltas import TimedeltaIndex
34
from typing_extensions import Self
45

56
from pandas._libs.tslibs import BaseOffset
67
from pandas._typing import (
78
S1,
9+
AxisIndex,
810
TimeUnit,
911
)
1012

@@ -15,10 +17,18 @@ class DatetimeIndexOpsMixin(ExtensionIndex[S1]):
1517
def freqstr(self) -> str | None: ...
1618
@property
1719
def is_all_dates(self) -> bool: ...
18-
def min(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
19-
def argmin(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
20-
def max(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
21-
def argmax(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
20+
def min(
21+
self, axis: AxisIndex | None = ..., skipna: bool = ..., *args, **kwargs
22+
) -> S1: ...
23+
def argmin(
24+
self, axis: AxisIndex | None = ..., skipna: bool = ..., *args, **kwargs
25+
) -> np.int64: ...
26+
def max(
27+
self, axis: AxisIndex | None = ..., skipna: bool = ..., *args, **kwargs
28+
) -> S1: ...
29+
def argmax(
30+
self, axis: AxisIndex | None = ..., skipna: bool = ..., *args, **kwargs
31+
) -> np.int64: ...
2232
def __rsub__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
2333
self, other: DatetimeIndexOpsMixin
2434
) -> TimedeltaIndex: ...

tests/test_indexes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,3 +1264,11 @@ def test_disallow_empty_index() -> None:
12641264
# From GH 826
12651265
if TYPE_CHECKING_INVALID_USAGE:
12661266
i0 = pd.Index() # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
1267+
1268+
1269+
def test_datetime_index_max_min_reductions() -> None:
1270+
dtidx = pd.DatetimeIndex(["2020-01-01", "2020-01-02"])
1271+
check(assert_type(dtidx.argmax(), np.int64), np.int64)
1272+
check(assert_type(dtidx.argmin(), np.int64), np.int64)
1273+
check(assert_type(dtidx.max(), pd.Timestamp), pd.Timestamp)
1274+
check(assert_type(dtidx.min(), pd.Timestamp), pd.Timestamp)

0 commit comments

Comments
 (0)