Skip to content

annualize: support years at or before 0; always warn about dropped records - #21

Open
nickmckay wants to merge 1 commit into
mainfrom
fix-annualize-year-zero
Open

nickmckay wants to merge 1 commit into
mainfrom
fix-annualize-year-zero

Conversation

@nickmckay

Copy link
Copy Markdown

Fixes #15 (and the error in fzhu2e#5).

  • utils.annualize(). When given a time axis, it now bins on numeric years instead of converting to datetime objects, so it works for years at or before 0. A new helper, _year_float2year_month(), assigns months the same way year_float2datetime() does, including leap years, and a month after the last month of the season goes to the next year's season (December for [-12, 1, 2]), as with the previous resample. The da path (used by ClimateField.annualize()) is unchanged.
  • ProxyDatabase.annualize(). It now always warns when it drops records and lists them, instead of only with verbose=True.

Same results for positive years. I compared the new and old utils.annualize() on 24,000 random series (monthly, whole-year, mid-year, irregular sub-annual and multi-year, and times on month boundaries, some with NaNs) and 8 seasons. The output is identical in every case, including the NaN gaps, and both versions raise in the same cases (no data in the requested months). The new version differs in two edge cases where the old one was wrong or failed:

  • Duplicate or unsorted times: the old one raised index must be monotonic for resampling, and the new one averages them.
  • A time within a minute of the end of a year: the old one put it in January of the same year, and the new one puts it in January of the next.

Tests. New tests cover records starting at 1.5, 0.5, -4.5 and -1161, sub-annual data across year 0, DJF across year 0, missing months, and ProxyDatabase.annualize() keeping records that start before year 0. All but the 1.5 case fail on main. The full suite passes (225 tests).

🤖 Generated with Claude Code

https://claude.ai/code/session_01TsdL1gpFWoD4LYexEPr6LD

…cords

utils.annualize converted year floats to datetime objects, which fail
for years <= 0 ('year 0 is out of range'), so ProxyDatabase.annualize
silently dropped every record that starts at or before year 0 (the
warning was printed only with verbose=True). The time-axis path now bins
on numeric years, with the same month assignment as year_float2datetime;
its output is identical to the previous version for positive years
(checked on 24,000 random series and seasons). ProxyDatabase.annualize
now always warns, listing the dropped records. See fzhu2e#5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TsdL1gpFWoD4LYexEPr6LD
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.

annualize fails for years <= 0, and ProxyDatabase.annualize silently drops those records

1 participant