fix: load pre-7.0 clustered NetCDF files with legacy original_data refs#742
Conversation
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>
|
Warning Review limit reached
Next review available in: 16 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Problem
Loading a clustered
FlowSystemfrom a NetCDF file written by a pre-7.0 flixopt fails with:Files written before flixopt 7.0 stored
clustering.original_data/clustering._metricsas:::original_data|.../:::metrics|...references in the clustering attrs JSON. Those targetarrays are no longer serialized (they only fed the removed
plot.compare()), and the currentClustering.__init__also rejects the_original_data_refs/_metrics_refskeys outright. So_restore_clustering— which resolves the structure against an empty arrays dict — raises.Fix
Drop the two legacy keys in
_restore_clusteringbefore resolving. Files written by 7.x areunaffected (they emit no such references).
Tests
Adds
TestLegacyClusteringBackwardCompat(in-memory + real NetCDF roundtrip). Verified the newtests 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, offrelease/7.2). This PRforward-ports the same fix to
mainso it isn't lost in the next (8.0.0) release.🤖 Generated with Claude Code