Skip to content

Commit 05fad40

Browse files
committed
fix: comments
1 parent 27e81a0 commit 05fad40

File tree

13 files changed

+112
-18
lines changed

13 files changed

+112
-18
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ ci:
33
autofix_prs: false
44
repos:
55
- repo: https://github.com/python/black
6-
rev: 25.1.0
6+
rev: 25.9.0
77
hooks:
88
- id: black
99
- repo: https://github.com/PyCQA/isort
1010
rev: 6.0.1
1111
hooks:
1212
- id: isort
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.12.10
14+
rev: v0.13.1
1515
hooks:
1616
- id: ruff-check
1717
args: [

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
763763
@overload
764764
def to_xml(
765765
self,
766-
path_or_buffer: Literal[None] = ...,
766+
path_or_buffer: None = ...,
767767
index: bool = ...,
768768
root_name: str | None = ...,
769769
row_name: str | None = ...,

pandas-stubs/core/groupby/indexing.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class GroupByNthSelector(Generic[_GroupByT]):
2727
def __call__(
2828
self,
2929
n: PositionalIndexer | tuple,
30-
dropna: Literal["any", "all", None] = ...,
30+
dropna: Literal["any", "all"] | None = ...,
3131
) -> DataFrame | Series: ...
3232
def __getitem__(self, n: PositionalIndexer | tuple) -> DataFrame | Series: ...

pandas-stubs/core/series.pyi

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,14 @@ class _SupportsMul(Protocol[_T_co]):
215215
def __mul__(self, value: Self, /) -> _T_co: ...
216216

217217
@type_check_only
218-
class _SupportsAddRMul(Protocol[_T_co]):
218+
class _SupportsAdd_MulFloat(Protocol[_T_co]):
219219
def __add__(self, value: Self, /) -> _T_co: ...
220220
def __mul__(self, value: float, /) -> _T_co: ...
221221

222+
@type_check_only
223+
class SupportsTruedivInt(Protocol[_T_co]):
224+
def __truediv__(self, value: int, /) -> _T_co: ...
225+
222226
class _iLocIndexerSeries(_iLocIndexer, Generic[S1]):
223227
# get item
224228
@overload
@@ -4474,7 +4478,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
44744478
) -> Timestamp: ...
44754479
@overload
44764480
def mean(
4477-
self: SupportsGetItem[Scalar, _SupportsAddRMul[S1]],
4481+
self: SupportsGetItem[Scalar, _SupportsAdd_MulFloat[S1]],
44784482
axis: AxisIndex | None = 0,
44794483
skipna: _bool = True,
44804484
level: None = ...,
@@ -4489,25 +4493,34 @@ class Series(IndexOpsMixin[S1], NDFrame):
44894493
level: None = ...,
44904494
numeric_only: _bool = False,
44914495
**kwargs: Any,
4496+
) -> Any: ...
4497+
@overload
4498+
def median(
4499+
self: Series[complex],
4500+
axis: AxisIndex | None = 0,
4501+
skipna: _bool = True,
4502+
level: None = ...,
4503+
numeric_only: _bool = False,
4504+
**kwargs: Any,
44924505
) -> float: ...
44934506
@overload
44944507
def median(
4495-
self: Series[Timestamp],
4508+
self: SupportsGetItem[Scalar, SupportsTruedivInt[S2]],
44964509
axis: AxisIndex | None = 0,
44974510
skipna: _bool = True,
44984511
level: None = ...,
44994512
numeric_only: _bool = False,
45004513
**kwargs: Any,
4501-
) -> Timestamp: ...
4514+
) -> S2: ...
45024515
@overload
45034516
def median(
4504-
self,
4517+
self: Series[Timestamp],
45054518
axis: AxisIndex | None = 0,
45064519
skipna: _bool = True,
45074520
level: None = ...,
45084521
numeric_only: _bool = False,
45094522
**kwargs: Any,
4510-
) -> S1: ...
4523+
) -> Timestamp: ...
45114524
def min(
45124525
self,
45134526
axis: AxisIndex | None = 0,

tests/series/arithmetic/float/test_floordiv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_floordiv_numpy_array() -> None:
9191
assert_type(left // c, Never)
9292

9393
# `numpy` typing gives the corresponding `ndarray`s in the static type
94-
# checking, where our `__rsub__` cannot override. At runtime, they lead to
94+
# checking, where our `__rfloordiv__` cannot override. At runtime, they lead to
9595
# errors or pd.Series.
9696
assert_type(b // left, "npt.NDArray[np.int8]")
9797
check(i // left, pd.Series, np.floating)

tests/series/arithmetic/int/test_floordiv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_floordiv_numpy_array() -> None:
9191
assert_type(left // c, Never)
9292

9393
# `numpy` typing gives the corresponding `ndarray`s in the static type
94-
# checking, where our `__rsub__` cannot override. At runtime, they lead to
94+
# checking, where our `__rfloordiv__` cannot override. At runtime, they lead to
9595
# errors or pd.Series.
9696
assert_type(b // left, "npt.NDArray[np.int8]")
9797
check(i // left, pd.Series, np.integer)

tests/series/arithmetic/timedelta/test_floordiv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_floordiv_numpy_array() -> None:
135135
check(assert_type(left // d, "pd.Series[int]"), pd.Series, np.integer)
136136

137137
# `numpy` typing gives the corresponding `ndarray`s in the static type
138-
# checking, where our `__rsub__` cannot override. At runtime, they lead to
138+
# checking, where our `__rfloordiv__` cannot override. At runtime, they lead to
139139
# errors or pd.Series.
140140
if TYPE_CHECKING_INVALID_USAGE:
141141
assert_type(b // left, "npt.NDArray[np.int8]")

tests/series/arithmetic/timedelta/test_truediv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_truediv_numpy_array() -> None:
161161
check(assert_type(left / d, "pd.Series[float]"), pd.Series, np.floating)
162162

163163
# `numpy` typing gives the corresponding `ndarray`s in the static type
164-
# checking, where our `__rsub__` cannot override. At runtime, they lead to
164+
# checking, where our `__rtruediv__` cannot override. At runtime, they lead to
165165
# errors or pd.Series.
166166
if TYPE_CHECKING_INVALID_USAGE:
167167
assert_type(b / left, "npt.NDArray[np.float64]")

tests/series/test_agg.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from typing import Any
2+
3+
import numpy as np
4+
import pandas as pd
5+
from typing_extensions import assert_type
6+
7+
from tests import (
8+
TYPE_CHECKING_INVALID_USAGE,
9+
check,
10+
pytest_warns_bounded,
11+
)
12+
13+
14+
def test_agg_any_float() -> None:
15+
series = pd.DataFrame({"A": [1.0, float("nan"), 2.0]})["A"]
16+
check(assert_type(series.median(), Any), np.float64)
17+
18+
19+
def test_agg_bool() -> None:
20+
series = pd.Series([True, False, True])
21+
check(assert_type(series.median(), float), np.float64)
22+
23+
24+
def test_agg_int() -> None:
25+
series = pd.Series([3, 1, 2])
26+
check(assert_type(series.median(), float), np.float64)
27+
28+
29+
def test_agg_float() -> None:
30+
series = pd.Series([3.0, float("nan"), 2.0])
31+
check(assert_type(series.median(), float), np.float64)
32+
33+
34+
def test_agg_complex() -> None:
35+
series = pd.Series([3j, 3 + 4j, 2j])
36+
with pytest_warns_bounded(
37+
np.exceptions.ComplexWarning,
38+
r"Casting complex values to real discards the imaginary part",
39+
):
40+
check(assert_type(series.median(), float), np.float64)
41+
42+
43+
def test_agg_str() -> None:
44+
series = pd.Series(["1", "a", "🐼"])
45+
if TYPE_CHECKING_INVALID_USAGE:
46+
series.median() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue]
47+
48+
49+
def test_agg_ts() -> None:
50+
series = pd.Series(pd.to_datetime(["2025-09-18", "2025-09-18", "2025-09-18"]))
51+
check(assert_type(series, "pd.Series[pd.Timestamp]"), pd.Series, pd.Timestamp)
52+
53+
check(assert_type(series.median(), pd.Timestamp), pd.Timestamp)
54+
55+
56+
def test_agg_td() -> None:
57+
series = pd.Series(pd.to_timedelta(["1 days", "2 days", "3 days"]))
58+
check(assert_type(series, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta)
59+
60+
check(assert_type(series.median(), pd.Timedelta), pd.Timedelta)

tests/series/test_cumul.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ def test_cumul_ts() -> None:
4949

5050
if TYPE_CHECKING_INVALID_USAGE:
5151
series.cumprod() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue]
52+
53+
54+
def test_cumul_td() -> None:
55+
series = pd.Series(pd.to_timedelta(["1 days", "2 days", "3 days"]))
56+
check(assert_type(series, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta)
57+
58+
if TYPE_CHECKING_INVALID_USAGE:
59+
series.cumprod() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue]

0 commit comments

Comments
 (0)