Repository navigation
Upgrade to pandas 3, keeping pandas 2 supported - #2955
Conversation
…which pandas 3 removed
…longer accepts 1H Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
…pling Pandas 3 reads timedelta(days=1) as a frequency of a fixed 24 hours, so daily steps would no longer land on local midnights after a DST change, as they did under pandas 2. This would undo #2907 for the GET sensor data endpoint, for example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
A pd.Timestamp is also a datetime, so it was returned as a datetime. With pandas 3's zoneinfo timezones, such a datetime in an hour that a DST change repeats never equals a time in another timezone (PEP 495). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
…licitly Pandas 3 no longer stores them in nanoseconds by default, so chart data and compressed belief records got timestamps in seconds instead of milliseconds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
Under pandas 3, text divided by a Timedelta leaves an object dtype rather than floats. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
Pandas 3 left the grouping column out of each group, and ignored the chained assignment that collected the contents (Copy-on-Write), so only the first annotation's content was shown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
Pandas 3 reads series[3] as a label rather than a position, and refuses to set a float into an integer column rather than upcasting it. In the storage scheduler, the constant penalty for preferring a full storage sooner was read with iloc[0][0]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
…ooded with Pandas4Warnings No more inplace reset_index, set_index or rename, positional arguments of sum, implicit sorting in concat, implicit date formats in to_json, Timestamp.utcnow or the d unit alias. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
…eprecates its epoch date format DataFrame.to_json(date_format="epoch") warns on every call under pandas 3.1, and pandas 3 floors negative durations where pandas 2 truncated them toward zero. Converting datetime and timedelta columns to milliseconds ourselves keeps the JSON for charts and annotations exactly as pandas 2 wrote it, without a warning per request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
pyproject still allows pandas 2 (pandas>=2.2.1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
📖 17 files changed · 1 added · 16 modified
Preview · build overview · flexmeasures · built Dec. 3, 2026, 11:38 a.m. UTC |
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…s a stepping stone It returns an offset, not a frequency. Its docstring now says it keeps the pandas 2 behaviour rather than converting correctly: a timedelta cannot tell P1D from PT24H, so both count as calendar days, until FlexMeasures keeps nominal and absolute durations apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
These tests fail on pandas 3 without to_calendar_offset: daily steps would fall at 23:00 after DST ends, and the day DST ends would no longer add up 25 hours. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA Signed-off-by: F.N. Claessen <claessen@seita.nl>
…o longer supports, and say why timely-beliefs 5.0.0 is required Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
Flix6x
left a comment
There was a problem hiding this comment.
Self-review before merging. Checked on pandas 2.3.3 and 3.1.2, at 1291e1a:
- Calendar days across DST. A daily index across the end of DST (25 October 2026, Amsterdam) keeps to local midnights on both versions. With
to_calendar_offsetreturning the 24-hour offset instead, pandas 3 drifts to 23:00 after the change and adds a sixth day, and the four new DST tests fail. So they test the fix. - What the PR leaves alone is fine. The forecasting pipelines and the
StorageSchedulerwork in UTC. The reaction-rules index steps by minutes.get_continuous_serieshands its resolution toTimedBelief.search, where timely-beliefs 5.0.0 applies the same calendar-day rule. - Chart JSON. On 500 random frames (also before 1970, with missing values and negative horizons),
with_epoch_millisecondswrites the same bytes on both versions, and the same as pandas 2's ownto_json. That holds for microsecond timestamps, which is what the database keeps. - Tests. The new tests and the touched parts pass on both versions: utils, planning, reporting, the forecasting pipeline, annotations, the sensor-data API (incl. DST), the assets API and the API schemas. CI is green apart from DCO.
Right after this comment I merge main into the branch (the only conflict is two new tests at the end of test_aggregator.py; both stay, and the reporting tests rerun on both versions before the push), plus one commit that drops initialize_index's branch for pandas < 1.4 (dead since pandas>=2.2.1) and notes in pyproject.toml why timely-beliefs 5.0.0 is required.
DCO fails on the commit from #2932, which had no sign-off there either. I set the check to pass, as that commit is Furqan's own contribution from #2932.
Not this PR's doing: daily values posted across a DST change still land an hour off, on pandas 2 as well (#2503).
Keeps both tests at the end of reporting/tests/test_aggregator.py: the one from #2804 and the DST test from this PR. Signed-off-by: F.N. Claessen <claessen@seita.nl>
|
Follow-ups of the review:
|
…er order its sources come in The lookup used one_deterministic_belief_per_event, which between sources of different types keeps the one listed first. That order came from the database, so a complete forecast saved before could hide a partial report recorded since, and test_a_complete_forecast_supersedes_a_partial_report_recorded_since failed whenever it ran on its own (and once in CI). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
…tor types Since #2804, an AggregatorReporter saves each event under the type of its inputs, so one reporter records as a forecaster, a reporter or a scheduler. Families of sources were keyed by name, type and model, which split such a reporter into unrelated sources: its versions were not compared, a complete aggregate did not replace a partial one of the same belief time (the higher source id decided), and a search naming both preferred whichever came first. - source_family: name and model, plus the type unless it is a data generator's type; used by _select_latest_version_and_belief_per_event, keep_latest_version and the aggregator's superseding lookup. - Sensor.search_data_sources returns sources in id order, not in whatever order the database returns. - The superseding lookup goes back to one_deterministic_belief_per_event (reverting aafbbef's workaround), which test_a_complete_forecast_supersedes_a_partial_report_recorded_since now passes on its own, too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
FlexMeasures moves to pandas 3, and keeps supporting pandas 2. It requires timely-beliefs 5.0.0, the first release that supports pandas 3 (SeitaBV/timely-beliefs#276).
This includes the fix from #2932 (cherry-picked, so its author keeps the credit), as part of one effort to support pandas 3.
Changes
to_calendar_offsetcounts whole-day resolutions as calendar days again. It is used ininitialize_index, the aggregator, profit and process schedulers, and the storage scheduler's resampling. This is a stepping stone, not a correct conversion: a timedelta cannot tellP1D(nominal) fromPT24H(absolute), so both count as calendar days, as they did on pandas 2. New tests fail on pandas 3 without it.to_json(date_format="epoch").with_epoch_millisecondswrites the same JSON that pandas 2 wrote, including how it truncated sub-millisecond values.apply_offset_chainreturns a Timestamp when given one.iloc.groupby().applyincluding the grouping columns.1h, not1H.inplace=Truein forecasting, positionalsumarguments, unsorted concat,Timestamp.utcnowand thedunit. The remaining Pandas4Warnings come from darts, and are silent by default outside__main__, because Pandas4Warning is a DeprecationWarning.Tests
The full suite passes on both pandas versions, with timely-beliefs 5.0.0 from PyPI, after merging main:
New tests:
test_to_calendar_offset,test_to_calendar_offset_steps_by_local_midnights_across_dst,test_initialize_index_steps_by_calendar_days_across_dstandtest_aggregator_resamples_to_calendar_days_across_dsttest_prepare_annotations_for_chart_stacks_annotations_with_the_same_endtest_with_epoch_milliseconds_writes_the_json_that_pandas_2_wroteSpeed
From
flexmeasures/data/scripts/benchmark_search_postprocessing.pyat 100,000 rows, pandas 2.3.3 against pandas 3.1.2 (single run, medians):keep_latest_version(1 source)keep_latest_version(3 sources, distinct groups)keep_latest_version(3 sources, 2 versions of one)keep_latest_version(probabilistic, 3 sources)compress_belief_records(3 sources, distinct groups)Lock
uv.lockmoves to pandas 3.1.2 (only pandas changes), so CI and the Docker image run on pandas 3.pyproject.tomlstill allows pandas 2 (pandas>=2.2.1), which no longer runs in CI but passes the suite locally (see above).🤖 Generated with Claude Code
https://claude.ai/code/session_01DWv6v3WRq4uE4AaVmZiHWA