Skip to content

Preserve Duration state in pickle and shallow copies - #1024

Open
GreedyC wants to merge 1 commit into
python-pendulum:masterfrom
GreedyC:codex/preserve-duration-pickle-state
Open

GreedyC wants to merge 1 commit into
python-pendulum:masterfrom
GreedyC:codex/preserve-duration-pickle-state

Conversation

@GreedyC

@GreedyC GreedyC commented Oct 2, 2026

Copy link
Copy Markdown

Fixes #1023.

Preserve Duration's instance state alongside the existing timedelta reduction. Pickle round-trips and shallow copies then retain the year/month components rather than turning them into approximate weeks/days. Interval's existing reduction is unchanged.

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code. No new API: restores the existing value's calendar components.

Validation:

  • 19 regression cases fail before the fix, covering every pickle protocol and positive/negative/mixed-sign calendar components.
  • Pure-Python suites on Python 3.10 and 3.12: 1,868 passed, 3 skipped each.
  • Pinned Ruff 0.14.11 lint/format checks pass; mypy 1.13.0 passes for all 228 source files.
  • The Rust extension variant was not run locally. The change is confined to Python Duration reduction.

AI assistance: Codex.

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.

Duration pickle and shallow copy lose year and month components

1 participant