Skip to content
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
44 changes: 40 additions & 4 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2344,30 +2344,66 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
axis: Axis | None = ...,
level: Level | None = None,
) -> Self: ...
@overload
def max(
self,
axis: Axis | None = 0,
axis: None,
skipna: _bool | None = True,
numeric_only: _bool = False,
**kwargs: Any,
) -> Scalar: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably further restrict to _OrderableT from pandas-stubs/_libs/intervals.pyi, instead of just Scalar. But this can be done in a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a type that can be returned? I thought it was more of a generic for Interval or something like that. I have left it for later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, either. @Dr-Irv can we return _OrderableT?

@overload
def max(
self,
axis: Axis = 0,
skipna: _bool | None = True,
numeric_only: _bool = False,
**kwargs: Any,
) -> Series: ...
@overload
def mean(
self,
axis: Axis | None = 0,
axis: None,
skipna: _bool | None = True,
numeric_only: _bool = False,
**kwargs: Any,
) -> Scalar: ...
@overload
def mean(
self,
axis: Axis = 0,
skipna: _bool | None = True,
numeric_only: _bool = False,
**kwargs: Any,
) -> Series: ...
@overload
def median(
self,
axis: Axis | None = 0,
axis: None,
skipna: _bool | None = True,
numeric_only: _bool = False,
**kwargs: Any,
) -> Scalar: ...
@overload
def median(
self,
axis: Axis = 0,
skipna: _bool | None = True,
numeric_only: _bool = False,
**kwargs: Any,
) -> Series: ...
@overload
def min(
self,
axis: Axis | None = 0,
axis: None,
skipna: _bool | None = True,
numeric_only: _bool = False,
**kwargs: Any,
) -> Scalar: ...
@overload
def min(
self,
axis: Axis = 0,
skipna: _bool | None = True,
numeric_only: _bool = False,
**kwargs: Any,
Expand Down
12 changes: 8 additions & 4 deletions tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,14 @@ def test_types_cumsum() -> None:

def test_types_min() -> None:
s = pd.Series([1, 2, 3, np.nan])
s.min()
s.min(axis=0)
s.groupby(level=0).min()
s.min(skipna=False)
check(assert_type(s.min(), float), np.floating)
check(assert_type(s.min(axis=0), float), np.floating)
check(
assert_type(s.groupby(level=0).min(), "pd.Series[float]"),
pd.Series,
np.floating,
)
check(assert_type(s.min(skipna=False), float), np.floating)


def test_types_max() -> None:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ def test_types_mean() -> None:
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
check(assert_type(df.mean(), pd.Series), pd.Series)
check(assert_type(df.mean(axis=0), pd.Series), pd.Series)
check(assert_type(df.mean(axis=None), Scalar), np.floating)
check(assert_type(df.groupby(level=0).mean(), pd.DataFrame), pd.DataFrame)
check(
assert_type(df.mean(axis=1, skipna=True, numeric_only=False), pd.Series),
Expand All @@ -724,6 +725,7 @@ def test_types_median() -> None:
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
check(assert_type(df.median(), pd.Series), pd.Series)
check(assert_type(df.median(axis=0), pd.Series), pd.Series)
check(assert_type(df.median(axis=None), Scalar), np.floating)
check(assert_type(df.groupby(level=0).median(), pd.DataFrame), pd.DataFrame)
check(
assert_type(df.median(axis=1, skipna=True, numeric_only=False), pd.Series),
Expand Down Expand Up @@ -820,12 +822,14 @@ def test_types_min() -> None:
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
check(assert_type(df.min(), pd.Series), pd.Series)
check(assert_type(df.min(axis=0), pd.Series), pd.Series)
check(assert_type(df.min(axis=None), Scalar), np.integer)


def test_types_max() -> None:
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
check(assert_type(df.max(), pd.Series), pd.Series)
check(assert_type(df.max(axis=0), pd.Series), pd.Series)
check(assert_type(df.max(axis=None), Scalar), np.integer)


def test_types_quantile() -> None:
Expand Down