Skip to content

type datetimeindex max/min reductions #1134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pandas-stubs/core/indexes/datetimelike.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import numpy as np
from pandas.core.indexes.extension import ExtensionIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
from typing_extensions import Self

from pandas._libs.tslibs import BaseOffset
from pandas._typing import (
S1,
AxisIndex,
TimeUnit,
)

Expand All @@ -15,10 +17,18 @@ class DatetimeIndexOpsMixin(ExtensionIndex[S1]):
def freqstr(self) -> str | None: ...
@property
def is_all_dates(self) -> bool: ...
def min(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
def argmin(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
def max(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
def argmax(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
def min(
self, axis: AxisIndex | None = ..., skipna: bool = ..., *args, **kwargs
) -> S1: ...
def argmin(
self, axis: AxisIndex | None = ..., skipna: bool = ..., *args, **kwargs
) -> np.int64: ...
def max(
self, axis: AxisIndex | None = ..., skipna: bool = ..., *args, **kwargs
) -> S1: ...
def argmax(
self, axis: AxisIndex | None = ..., skipna: bool = ..., *args, **kwargs
) -> np.int64: ...
def __rsub__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: DatetimeIndexOpsMixin
) -> TimedeltaIndex: ...
Expand Down
8 changes: 8 additions & 0 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,3 +1201,11 @@ def test_disallow_empty_index() -> None:
# From GH 826
if TYPE_CHECKING_INVALID_USAGE:
i0 = pd.Index() # type: ignore[call-overload] # pyright: ignore[reportCallIssue]


def test_datetime_index_max_min_reductions() -> None:
dtidx = pd.DatetimeIndex(["2020-01-01", "2020-01-02"])
check(assert_type(dtidx.argmax(), np.int64), np.int64)
check(assert_type(dtidx.argmin(), np.int64), np.int64)
check(assert_type(dtidx.max(), pd.Timestamp), pd.Timestamp)
check(assert_type(dtidx.min(), pd.Timestamp), pd.Timestamp)