Skip to content

Commit 0a9f5a2

Browse files
committed
fix: comments
1 parent e411ea0 commit 0a9f5a2

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ from datetime import (
55
tzinfo as _tzinfo,
66
)
77
from typing import (
8-
Any,
98
Generic,
109
Literal,
1110
TypeVar,
@@ -444,7 +443,7 @@ class TimedeltaIndexProperties(
444443
@type_check_only
445444
class DtDescriptor:
446445
@overload
447-
def __get__(self, instance: Series[Never], owner: type[Series]) -> Any: ...
446+
def __get__(self, instance: Series[Never], owner: type[Series]) -> Properties: ...
448447
@overload
449448
def __get__(
450449
self, instance: Series[Timestamp], owner: type[Series]

pandas-stubs/core/series.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ from pandas.core.api import (
5656
Int32Dtype as Int32Dtype,
5757
Int64Dtype as Int64Dtype,
5858
)
59+
from pandas.core.arrays.boolean import BooleanDtype
5960
from pandas.core.arrays.categorical import CategoricalAccessor
6061
from pandas.core.arrays.datetimes import DatetimeArray
6162
from pandas.core.arrays.timedeltas import TimedeltaArray
@@ -843,6 +844,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
843844
@overload
844845
def diff(self: Series[_bool], periods: int = ...) -> Series: ...
845846
@overload
847+
def diff(
848+
self: Series[BooleanDtype], periods: int = ...
849+
) -> Series[BooleanDtype]: ...
850+
@overload
846851
def diff(self: Series[Period], periods: int = ...) -> OffsetSeries: ...
847852
@overload
848853
def diff(self: Series[Interval], periods: int = ...) -> Never: ...

tests/scalars/__init__.py

Whitespace-only changes.

tests/test_scalars.py renamed to tests/scalars/test_scalars.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ def test_interval_math() -> None:
287287
pd.Interval,
288288
)
289289

290+
if TYPE_CHECKING_INVALID_USAGE:
291+
_i = interval_i - pd.Interval(1, 2) # type: ignore[type-var] # pyright: ignore[reportOperatorIssue]
292+
_f = interval_f - pd.Interval(1.0, 2.0) # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
293+
_ts = interval_ts - pd.Interval( # type: ignore[operator]
294+
pd.Timestamp(2025, 9, 29), pd.Timestamp(2025, 9, 30), closed="both"
295+
) # pyright: ignore[reportOperatorIssue]
296+
_td = interval_td - pd.Interval( # type: ignore[operator]
297+
pd.Timedelta(1, "ns"), pd.Timedelta(2, "ns")
298+
) # pyright: ignore[reportOperatorIssue]
299+
290300

291301
def test_interval_cmp():
292302
interval_i = pd.Interval(0, 1, closed="left")

tests/series/test_properties.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import (
22
TYPE_CHECKING,
3-
Any,
43
)
54

65
import numpy as np
@@ -12,6 +11,7 @@
1211
from pandas.core.indexes.accessors import (
1312
DatetimeProperties,
1413
PeriodProperties,
14+
Properties,
1515
TimedeltaProperties,
1616
)
1717
from typing_extensions import assert_type
@@ -45,8 +45,9 @@ def test_dt_property() -> None:
4545

4646
if TYPE_CHECKING_INVALID_USAGE:
4747
s = pd.DataFrame({"a": [1]})["a"]
48-
assert_type(s.dt, Any)
49-
assert_type(s.dt.year, Any)
48+
# python/mypy#19952: mypy believes Properties and its subclasses have a
49+
# conflict and gives Any for s.dt
50+
assert_type(s.dt, Properties) # type: ignore[assert-type]
5051
_1 = pd.Series([1]).dt # type: ignore[arg-type] # pyright: ignore[reportAttributeAccessIssue]
5152

5253

tests/series/test_series.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,8 +3508,25 @@ def test_diff() -> None:
35083508
pd.Series([True, True, False, False, True]).diff(), "pd.Series[Any]"
35093509
),
35103510
pd.Series,
3511-
object,
3511+
bool,
3512+
index_to_check_for_type=-1,
35123513
)
3514+
# nullable bool -> nullable bool
3515+
with pytest_warns_bounded(
3516+
UserWarning,
3517+
r"Instantiating BooleanDtype without any arguments.Pass a BooleanDtype instance to silence this warning.",
3518+
):
3519+
check(
3520+
assert_type(
3521+
pd.Series(
3522+
[True, True, False, False, True], dtype=pd.BooleanDtype
3523+
).diff(),
3524+
"pd.Series[pd.BooleanDtype]",
3525+
),
3526+
pd.Series,
3527+
np.bool_,
3528+
index_to_check_for_type=-1,
3529+
)
35133530
# Any -> float
35143531
s_o = s.astype(object)
35153532
assert_type(s_o, "pd.Series[Any]")
@@ -3519,22 +3536,20 @@ def test_diff() -> None:
35193536
assert_type(s.astype(complex).diff(), "pd.Series[complex]"), pd.Series, complex
35203537
)
35213538

3522-
def _diff_invalid0(): # pyright: ignore[reportUnusedFunction]
3523-
# interval -> TypeError: IntervalArray has no 'diff' method. Convert to a suitable dtype prior to calling 'diff'.
3524-
assert_type(pd.Series([pd.Interval(0, 2), pd.Interval(1, 4)]).diff(), Never)
3525-
3526-
def _diff_invalid1() -> None: # pyright: ignore[reportUnusedFunction]
3539+
if TYPE_CHECKING_INVALID_USAGE:
35273540
# bytes -> numpy.core._exceptions._UFuncNoLoopError: ufunc 'subtract' did not contain a loop with signature matching types (dtype('S21'), dtype('S21')) -> None
35283541
pd.Series([1, 1, 2, 3, 5, 8]).astype(bytes).diff() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue]
35293542

3530-
def _diff_invalid2() -> None: # pyright: ignore[reportUnusedFunction]
35313543
# dtype -> TypeError: unsupported operand type(s) for -: 'type' and 'type'
35323544
pd.Series([str, int, bool]).diff() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue]
35333545

3534-
def _diff_invalid3() -> None: # pyright: ignore[reportUnusedFunction]
35353546
# str -> TypeError: unsupported operand type(s) for -: 'str' and 'str'
35363547
pd.Series(["a", "b"]).diff() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue]
35373548

3549+
def _diff_invalid0(): # pyright: ignore[reportUnusedFunction]
3550+
# interval -> TypeError: IntervalArray has no 'diff' method. Convert to a suitable dtype prior to calling 'diff'.
3551+
assert_type(pd.Series([pd.Interval(0, 2), pd.Interval(1, 4)]).diff(), Never)
3552+
35383553

35393554
def test_operator_constistency() -> None:
35403555
# created for #748

0 commit comments

Comments
 (0)