Skip to content

Include calendar components in duration division and remainder - #1051

Open
FanWu-ai wants to merge 1 commit into
python-pendulum:masterfrom
FanWu-ai:fix-calendar-duration-quotients-oct13
Open

FanWu-ai wants to merge 1 commit into
python-pendulum:masterfrom
FanWu-ai:fix-calendar-duration-quotients-oct13

Conversation

@FanWu-ai

Copy link
Copy Markdown
Contributor

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary

Addresses the duration-to-duration division and remainder part of #799.

duration(years=1) / duration(months=1) currently raises ZeroDivisionError: the conversion used by /, //, %, and divmod() omits both operands' calendar components. Nonzero fixed components can instead hide the problem and produce incorrect quotients or remainders.

Include the existing 365-day/year and 30-day/month approximations when these operations compare two durations. For example, one month divided by ten days is now 3.0, and one month modulo seven days is two days. Keep scalar arithmetic's separate calendar components unchanged. Intervals retain their actual elapsed time, and AbsoluteDuration retains its existing already-expanded storage representation.

This does not include the float-multiplication issue in #975 or native datetime.timedelta operand support in #1042.

Validation

On Linux with CPython 3.12.14, against master e06dacedc4cdea90fa1286b3965d180ab94cf251:

  • Pristine full suite: 1,871 passed, 3 existing skips.
  • Exact added regression/control cases on pristine source: 51 failed, 13 passed, with both Python and native implementations.
  • Final complete pure-Python, debug-native, and release-native suites: 1,935 passed, 3 existing skips each.
  • Full Mypy check: 228 source files passed.
  • All six pinned Prek hooks passed, including Ruff and Rust format/Clippy checks.
  • Strict documentation build, separate source/wheel builds, strict Twine checks, source-distribution installation, and installed-wheel complete suite passed.
  • Additional automated verification: 40,000 standard-library-reference quotient/remainder checks and an independent 4,800-case mixed Duration/Interval review passed.

The skips are one Windows-only test and two existing ZoneInfo POSIX-transition limitations. The hosted Python/OS matrix has not run on this change yet; no hosted pass is claimed.

Prepared and tested with OpenAI Codex assistance, including automated review. No human review is claimed.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 12, 2026 21:42
@codspeed

codspeed Bot commented Oct 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because we failed to resolve the symbols in the profiling trace. This happens when we fail to harvest information about language frames.

✅ 1 untouched benchmark


Comparing FanWu-ai:fix-calendar-duration-quotients-oct13 (a6b1722) with master (e06dace)

Open in CodSpeed

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant