GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TYP: allow floor division of Series[Any] by a timedelta scalar by Blizzeq · Pull Request #1968 · pandas-dev/pandas-stubs

Conversation

@Blizzeq

@Blizzeq Blizzeq commented Oct 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Closes Series[Any] // Timedelta(...) not supported #1904
  • Tests added (Please use assert_type() to assert the type of any return value)
  • If I used AI to develop this pull request, I prompted it to follow AGENTS.md.

Series[Any] // pd.Timedelta(...) was rejected by mypy, pyright, and pyrefly because timedelta scalars were only handled through Supports_ProtoFloorDiv, which cannot resolve type variables on Series[Any]. Instead of adding Series[Never] overloads, this widens other on the existing self: Series[Timedelta] overloads of floordiv and floordiv with timedelta | np.timedelta64. That lets Series[Any] // timedelta resolve to Series[int] while preserving invalid-operand diagnostics on concrete numeric types like Series[int]. Two invalid-usage assertions on untyped Series[Any] in test_floordiv_py_scalar are commented out since left_i is annotated pd.Series (Series[Any]).

AI Implementation Plan

Motivation

#1904 requires (data[0] - data[1]) // pd.Timedelta(seconds=1) (Series[Any] // Timedelta) to type-check cleanly across mypy, pyright, pyrefly, and ty without relying on Series[Never] overloads (which broke or risked breaking across type checker updates, see python/mypy#22011).

Solution and Alternatives

  • Chosen approach. Add timedelta | np.timedelta64 to other on Series.__floordiv__(self: Series[Timedelta], ...) and Series.floordiv(self: Series[Timedelta], ...) in pandas-stubs/core/series.pyi. Gradual typing matches self: Series[Any] against Series[Timedelta], returning Series[int], while concrete Series[int] (verified in tests/series/int/test_floordiv.py) does not match self: Series[Timedelta] and still fails static type checking.
  • Alternative rejected. Series[Never] overloads, which maintainers asked to avoid.

Verification

  • mypy pandas-stubs tests --no-incremental --strict passed (386 source files, 0 issues)
  • pyright passed (0 errors, 0 warnings)
  • poe pyrefly passed (0 diagnostics, 2,209 suppressed)
  • poe pytest_architecture passed (62 passed)
  • poe style passed (ruff check, codespell, isort, black, check-ignore-spacing, guard-dunders-posonly)
  • pytest tests/series/test_floordiv.py tests/series/int/test_floordiv.py tests/series/timedelta/test_floordiv.py passed (17 passed)
  • Caveat. Local .venv has ty 0.0.89 while pyproject.toml now requires ty>=0.0.100, so full poe ty awaits CI.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Blizzeq @claude
TYP: allow floor division of Series[Any] by a timedelta scalar
26e7c7a
Co-authored-by: claude-opus-5-5 <[email protected]>
@cmp0xff

cmp0xff commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Thank you @Blizzeq . I feel python/mypy#22106 may change how we design the overloads soon. Let's wait for the decision there.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@loicdiridollou loicdiridollou added the Blocked Requires external dependency before progressing label Oct 8, 2026
@cmp0xff

cmp0xff commented Oct 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Following python/mypy#22011 (sorry wrong reference earlier), maybe we have to close this one and find a new way for the [Never] hack? ty and pyright also seems to be moving in this direction astral-sh/ruff#29342 microsoft/pyright#11864. Also reported to pyrefly pyrefly-org/pyrefly#5205. cc @loicdiridollou @Dr-Irv

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Dr-Irv

Dr-Irv commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Yes, I think we will have to do that. It might be that we just have to make the methods allow wider arguments than we do now with the [Never] hack.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Blizzeq

Blizzeq commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Makes sense, closing this. Happy to help with the wider signatures once the direction is settled.

cmp0xff reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Blizzeq Blizzeq closed this Oct 14, 2026
This was referenced Nov 3, 2026
TYP: #1378 align Series __add__ family with __mul__ #1914
Closed
TYP: add Series.add/radd keywords and sequence addition cmp0xff/pandas-stubs#46
Draft
TYP: accept sequences and PeriodIndex in Series subtraction cmp0xff/pandas-stubs#47
Draft
@hector2394 hector2394 mentioned this pull request Nov 11, 2026
Series[Any] // Timedelta(...) not supported #1904
Closed
@cmp0xff

cmp0xff commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Hi @Blizzeq , if you have the capacity to make it work without the Never trick, you may reopen this PR / open a new PR. Otherwise @hector2394 would probably propose a solution also without the Never trick.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Blizzeq and others added 2 commits November 14, 2026 14:56
@Blizzeq
Merge remote-tracking branch 'upstream/main' into typ/1904-series-any…
22410bf
…-floordiv-timedelta
@Blizzeq
TYP: allow floor division of Series[Any] by a timedelta scalar withou…
344f700
…t Series[Never]

Co-authored-by: Gemini 3.1 Pro <[email protected]>
@Blizzeq Blizzeq reopened this Nov 14, 2026
@Blizzeq Blizzeq changed the title TYP: allow floor division of Series[Any] by a timedelta scalar TYP: allow floor division of Series[Any] by a timedelta scalar Nov 14, 2026
@Blizzeq

Blizzeq commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for pinging me, @cmp0xff, and thanks @hector2394 for raising this. I merged main and updated the branch to add timedelta | np.timedelta64 directly to the existing self: Series[Timedelta] overloads on __floordiv__ and floordiv without any Series[Never] overloads, so concrete Series[int] rejection (tested in tests/series/int/test_floordiv.py) stays intact. Reopening this PR now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmp0xff cmp0xff removed the Blocked Requires external dependency before progressing label Nov 15, 2026
cmp0xff
cmp0xff requested changes Nov 15, 2026
View reviewed changes
Comment thread pandas-stubs/core/series.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pandas-stubs/core/series.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Blizzeq
TYP: reuse ScalarArrayIndexSeriesTimedelta in Series[Timedelta] floor…
ef71252
…div overloads
cmp0xff
cmp0xff requested changes Nov 17, 2026
View reviewed changes
Comment thread pandas-stubs/core/series.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Blizzeq
TST: cover timedelta sequence in Series[Timedelta] floordiv tests
024df7a
Co-authored-by: Gemini 3.1 Pro <[email protected]>
cmp0xff
cmp0xff approved these changes Nov 22, 2026
View reviewed changes
cmp0xff
cmp0xff approved these changes Nov 22, 2026
View reviewed changes

@cmp0xff cmp0xff left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you @Blizzeq

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cmp0xff
cmp0xff merged commit 83de5cd into pandas-dev:main Nov 22, 2026
18 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cmp0xff cmp0xff cmp0xff approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Series[Any] // Timedelta(...) not supported

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Blizzeq @cmp0xff @Dr-Irv @loicdiridollou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.