Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8a99cf4
refactor: only drop TimestampSeries https://github.com/pandas-dev/pan…
cmp0xff Jul 13, 2025
ed69ec5
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274/fi…
cmp0xff Jul 28, 2025
f1cf19f
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Aug 2, 2025
ad0ee10
less mypy ignore
cmp0xff Aug 4, 2025
2dada6d
fix: even less mypy ignores
cmp0xff Aug 5, 2025
0359fd5
refactor(comment): https://github.com/pandas-dev/pandas-stubs/pull/12…
cmp0xff Aug 5, 2025
34703d7
feat: sub
cmp0xff Aug 5, 2025
c4d657e
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274/fi…
cmp0xff Aug 6, 2025
1eeb809
fix: pyrefly
cmp0xff Aug 6, 2025
ceff1fe
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274/fi…
cmp0xff Aug 6, 2025
dd8baff
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274#di…
cmp0xff Aug 6, 2025
8a07eca
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274#di…
cmp0xff Aug 6, 2025
3458fc9
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274#di…
cmp0xff Aug 6, 2025
d333902
fix: reduce ignore
cmp0xff Aug 6, 2025
368c3ff
refactor: explain a temporary failure
cmp0xff Aug 7, 2025
2f661ae
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Aug 7, 2025
15996ff
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274#di…
cmp0xff Aug 7, 2025
c9c46b0
feat: arithmetic sub
cmp0xff Aug 8, 2025
e3447cf
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1312#di…
cmp0xff Aug 8, 2025
672009e
feat(comment): https://github.com/pandas-dev/pandas-stubs/pull/1312#d…
cmp0xff Aug 11, 2025
5dab881
Merge branch 'main' into feature/cmp0xff/arithmetic-sub
cmp0xff Aug 14, 2025
1e9b11d
fix(comment): completeness https://github.com/pandas-dev/pandas-stubs…
cmp0xff Aug 14, 2025
6484af7
feat(series): arithmetic mul
cmp0xff Aug 8, 2025
72c2bd1
Merge branch 'feature/cmp0xff/arithmetic-mul' into hotfix/cmp0xff/gh7…
cmp0xff Aug 16, 2025
0657417
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Aug 19, 2025
7a87d18
fix: type asserts
cmp0xff Aug 20, 2025
6469196
feat: tests for addition
cmp0xff Aug 20, 2025
aac6cff
fix(mypy): attempt for python > 310
cmp0xff Aug 20, 2025
72208c7
feat: tests for subtraction
cmp0xff Aug 20, 2025
533b15d
fix: pyright
cmp0xff Aug 20, 2025
ce06dc2
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274#di…
cmp0xff Aug 20, 2025
f855f86
refactor: revert unused design
cmp0xff Aug 20, 2025
8a01e12
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Aug 22, 2025
0a84cd0
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Aug 27, 2025
253e61a
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Sep 2, 2025
f736d55
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Sep 4, 2025
3ff2c36
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Sep 11, 2025
f10e990
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Sep 13, 2025
4e5e68c
feat: progressive philosophy
cmp0xff Sep 13, 2025
55fdfe9
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
cmp0xff Sep 14, 2025
6572abc
fix(pytest): remove invalid tests
cmp0xff Sep 15, 2025
7b380b3
fix: comment
cmp0xff Sep 15, 2025
e7705e4
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274/fi…
cmp0xff Sep 15, 2025
b487bc9
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274#di…
cmp0xff Sep 15, 2025
ff37521
chore(philosophy): first draft
cmp0xff Sep 15, 2025
61a9703
fix(pyright): median
cmp0xff Sep 15, 2025
e2b1901
fix: comment
cmp0xff Sep 16, 2025
a488907
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274#pu…
cmp0xff Sep 17, 2025
a0ae00d
fix(comment): test_sub
cmp0xff Sep 17, 2025
ed7de8d
fix: typo
cmp0xff Sep 17, 2025
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
Prev Previous commit
Next Next commit
fix(comment): test_sub
  • Loading branch information
cmp0xff committed Sep 17, 2025
commit a0ae00dd8e6e272cba3c0c86f626126eba3943d5
16 changes: 12 additions & 4 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3050,10 +3050,13 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: int = 0,
) -> TimedeltaSeries: ...
@overload
def __rsub__(
def __rsub__( # type: ignore[overload-overlap]
self: Series[Never],
other: (
complex
| datetime
| np.datetime64
| np_ndarray_dt
| NumListLike
| Index[T_COMPLEX]
| Series[T_COMPLEX]
Expand Down Expand Up @@ -3160,13 +3163,18 @@ class Series(IndexOpsMixin[S1], NDFrame):
) -> Series[Timedelta]: ...
@overload
def __rsub__(
self: Series[Timedelta], other: Series[Timestamp]
self: Series[Timedelta],
other: datetime | np.datetime64 | np_ndarray_dt | Series[Timestamp],
) -> Series[Timestamp]: ...
@overload
def rsub(
def rsub( # type: ignore[overload-overlap]
self: Series[Never],
other: (
complex
| datetime
| Sequence[datetime]
| np.datetime64
| np_ndarray_dt
| NumListLike
| Index[T_COMPLEX]
| Series[T_COMPLEX]
Expand Down Expand Up @@ -3312,7 +3320,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def rsub(
self: Series[Timedelta],
other: Series[Timestamp],
other: datetime | np.datetime64 | np_ndarray_dt | Series[Timestamp],
level: Level | None = None,
fill_value: float | None = None,
axis: int = 0,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = ">=1.1.405"
ty = ">=0.0.1a20"
pyrefly = ">=0.32.0"
pyrefly = ">=0.33.0"
poethepoet = ">=0.16.5"
loguru = ">=0.6.0"
typing-extensions = ">=4.4.0"
Expand Down
72 changes: 63 additions & 9 deletions tests/series/arithmetic/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# left operands
left_i = pd.DataFrame({"a": [1, 2, 3]})["a"]
left_ts = pd.DataFrame({"a": [anchor + timedelta(hours=h + 1) for h in range(3)]})["a"]
left_td = pd.DataFrame({"a": [timedelta(hours=h, minutes=1) for h in range(3)]})["a"]


def test_sub_i_py_scalar() -> None:
Expand Down Expand Up @@ -154,23 +155,44 @@ def test_sub_i_pd_series() -> None:


def test_sub_ts_py_datetime() -> None:
"""Test pd.Series[Any] (Timestamp) - Python native datetime"""
"""Test pd.Series[Any] (Timestamp | Timedelta) - Python native datetime"""
s = anchor
a = [s + timedelta(minutes=m) for m in range(3)]

check(assert_type(left_ts - s, "TimedeltaSeries"), pd.Series, pd.Timedelta)
if TYPE_CHECKING_INVALID_USAGE:
# Series[Any] (Timestamp) - Sequence[datetime] should work, see pandas-dev/pandas#62353
_1 = left_ts - a # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
# Series[Any] (Timedelta) - datetime fails at runtime,
# which cannot be revealed by our static type checking
# _2 = left_td - s
if TYPE_CHECKING_INVALID_USAGE:
# Series[Any] (Timedelta) - Sequence[datetime] is not supported by Pandas,
# see pandas-dev/pandas#62353. Even if such __sub__ is supported
# it will fail at runtime here,
# which cannot be revealed by our static type checking
_3 = left_td - a # type: ignore[operator] # pyright: ignore[reportOperatorIssue]

check(assert_type(s - left_ts, "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(s - left_ts, pd.Series), pd.Series, pd.Timedelta)
if TYPE_CHECKING_INVALID_USAGE:
# Sequence[datetime] - Series[Any] (Timestamp) should work, see pandas-dev/pandas#62353
_5 = a - left_ts # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
check(assert_type(s - left_td, pd.Series), pd.Series, pd.Timestamp)
if TYPE_CHECKING_INVALID_USAGE:
# Sequence[datetime] - Series[Any] (Timedelta) should work, see pandas-dev/pandas#62353
_7 = a - left_td # type: ignore[operator] # pyright: ignore[reportOperatorIssue]

check(assert_type(left_ts.sub(s), "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(left_ts.sub(a), "TimedeltaSeries"), pd.Series, pd.Timedelta)
# Series[Any] (Timedelta).sub(datetime or Sequence[datetime]) fails at runtime,
# which cannot be revealed by our static type checking
# left_td.sub(s)
# left_td.sub(a)

check(assert_type(left_ts.rsub(s), "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(left_ts.rsub(a), "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(left_ts.rsub(s), pd.Series), pd.Series, pd.Timedelta)
check(assert_type(left_ts.rsub(a), pd.Series), pd.Series, pd.Timedelta)
check(assert_type(left_td.rsub(s), pd.Series), pd.Series, pd.Timestamp)
check(assert_type(left_td.rsub(a), pd.Series), pd.Series, pd.Timestamp)


def test_sub_ts_numpy_datetime() -> None:
Expand All @@ -180,23 +202,41 @@ def test_sub_ts_numpy_datetime() -> None:

check(assert_type(left_ts - s, "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(left_ts - a, "TimedeltaSeries"), pd.Series, pd.Timedelta)
# Series[Any] (Timedelta) - np.datetime64 or np.NDArray[np.datetime64]
# fails at runtime,
# which cannot be revealed by our static type checking
# left_td - s
# left_td - a

# `numpy` typing gives the corresponding `ndarray`s in the static type
# checking, where our `__rsub__` cannot override. At runtime, they return
# `Series`.
# microsoft/pyright#10924
check(assert_type(s - left_ts, "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(s - left_ts, pd.Series), pd.Series, pd.Timedelta)
check(
assert_type(a - left_ts, Any), # pyright: ignore[reportAssertTypeFailure]
pd.Series,
pd.Timedelta,
)
check(assert_type(s - left_td, pd.Series), pd.Series, pd.Timestamp)
check(
assert_type(a - left_td, Any), # pyright: ignore[reportAssertTypeFailure]
pd.Series,
pd.Timestamp,
)

check(assert_type(left_ts.sub(s), "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(left_ts.sub(a), "TimedeltaSeries"), pd.Series, pd.Timedelta)
# Series[Any] (Timedelta).sub(np.datetime64 or np.NDArray[np.datetime64])
# fails at runtime,
# which cannot be revealed by our static type checking
# left_td.sub(s)
# left_td.sub(a)

check(assert_type(left_ts.rsub(s), "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(left_ts.rsub(a), "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(left_ts.rsub(s), pd.Series), pd.Series, pd.Timedelta)
check(assert_type(left_ts.rsub(a), pd.Series), pd.Series, pd.Timedelta)
check(assert_type(left_td.rsub(s), pd.Series), pd.Series, pd.Timestamp)
check(assert_type(left_td.rsub(a), pd.Series), pd.Series, pd.Timestamp)


def test_sub_ts_pd_datetime() -> None:
Expand All @@ -206,17 +246,31 @@ def test_sub_ts_pd_datetime() -> None:

check(assert_type(left_ts - s, "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(left_ts - a, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta)
# Series[Any] (Timedelta) - Timestamp or Seriesp[Timestamp]
# fails at runtime,
# which cannot be revealed by our static type checking
# left_td - s
# left_td - a

check(assert_type(s - left_ts, "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(s - left_ts, pd.Series), pd.Series, pd.Timedelta)
check(assert_type(a - left_ts, pd.Series), pd.Series, pd.Timedelta)
check(assert_type(s - left_td, pd.Series), pd.Series, pd.Timestamp)
check(assert_type(a - left_td, pd.Series), pd.Series, pd.Timestamp)

check(assert_type(left_ts.sub(s), "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(
assert_type(left_ts.sub(a), "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta
)
# Series[Any] (Timedelta).sub(Timestamp or Seriesp[Timestamp])
# fails at runtime,
# which cannot be revealed by our static type checking
# left_td.sub(s)
# left_td.sub(a)

check(assert_type(left_ts.rsub(s), "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(left_ts.rsub(s), pd.Series), pd.Series, pd.Timedelta)
check(assert_type(left_ts.rsub(a), pd.Series), pd.Series, pd.Timedelta)
check(assert_type(left_td.rsub(s), pd.Series), pd.Series, pd.Timestamp)
check(assert_type(left_td.rsub(a), pd.Series), pd.Series, pd.Timestamp)


def test_sub_str_py_str() -> None:
Expand Down
Loading