Skip to content

fix: load pre-7.0 clustered NetCDF files with legacy original_data refs#742

Merged
FBumann merged 1 commit into
mainfrom
fix/legacy-clustering-load-main
Jul 23, 2026
Merged

fix: load pre-7.0 clustered NetCDF files with legacy original_data refs#742
FBumann merged 1 commit into
mainfrom
fix/legacy-clustering-load-main

Conversation

@FBumann

@FBumann FBumann commented Jul 23, 2026

Copy link
Copy Markdown
Member

Problem

Loading a clustered FlowSystem from a NetCDF file written by a pre-7.0 flixopt fails with:

OSError: Failed to load FlowSystem from NetCDF file ...:
Referenced DataArray 'original_data|...|fixed_relative_profile' not found in dataset

Files written before flixopt 7.0 stored clustering.original_data / clustering._metrics as
:::original_data|... / :::metrics|... references in the clustering attrs JSON. Those target
arrays are no longer serialized (they only fed the removed plot.compare()), and the current
Clustering.__init__ also rejects the _original_data_refs / _metrics_refs keys outright. So
_restore_clustering — which resolves the structure against an empty arrays dict — raises.

Fix

Drop the two legacy keys in _restore_clustering before resolving. Files written by 7.x are
unaffected (they emit no such references).

Tests

Adds TestLegacyClusteringBackwardCompat (in-memory + real NetCDF roundtrip). Verified the new
tests fail without the fix (reproducing the exact error) and pass with it.

Release note

Already shipped to users on the 7.2.x line as 7.2.2 (tag v7.2.2, off release/7.2). This PR
forward-ports the same fix to main so it isn't lost in the next (8.0.0) release.

🤖 Generated with Claude Code

Files written before flixopt 7.0 stored clustering.original_data and
clustering._metrics as ':::original_data|...' / ':::metrics|...' references
in the clustering attrs JSON. The target arrays are no longer serialized
(they only fed the removed plot.compare()), and the current Clustering
constructor rejects the _original_data_refs / _metrics_refs keys outright.

As a result, FlowSystem.from_netcdf() on any such file raised
"Referenced DataArray 'original_data|...' not found in dataset".

Drop the two legacy keys in _restore_clustering before resolving so old
files remain loadable. 7.2.x files themselves are unaffected (they write
no such references).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@FBumann, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 16 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8200ee5f-d202-4907-ab61-7cc3ec5b7b82

📥 Commits

Reviewing files that changed from the base of the PR and between cc56774 and 6201fcc.

📒 Files selected for processing (2)
  • flixopt/io.py
  • tests/test_clustering/test_clustering_io.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/legacy-clustering-load-main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@FBumann
FBumann enabled auto-merge (squash) July 23, 2026 06:29
@FBumann
FBumann merged commit 6962e5e into main Jul 23, 2026
11 checks passed
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