Skip to content

Fix JSON encoding, Comparison coords, and docs warnings#599

Open
FBumann wants to merge 5 commits intomainfrom
feature/coords-merge-comparison
Open

Fix JSON encoding, Comparison coords, and docs warnings#599
FBumann wants to merge 5 commits intomainfrom
feature/coords-merge-comparison

Conversation

@FBumann
Copy link
Member

@FBumann FBumann commented Feb 4, 2026

Summary

Patch release v6.0.1 with bug fixes:

  • JSON Encoding: Fixed special characters (Ä, ö, etc.) being escaped in saved JSON/NetCDF files by adding ensure_ascii=False to json.dumps() calls in io.py
  • Comparison Coordinates: Fixed component coordinate becoming (case, contributor) shaped after concatenation in Comparison class. Non-index coordinates are now properly merged before concat
  • Clustering Notebooks: Added explicit preserve_n_clusters=True to all ExtremeConfig calls to fix FutureWarning from tsam v3.1
  • Docs Workflow: Added workflow_dispatch inputs for manual docs deployment with version selection

Test plan

  • Verify JSON files preserve Unicode characters when saved/loaded
  • Verify Comparison.flow_hours has correct component coordinate shape
  • Verify docs build without FutureWarning from tsam
  • Verify docs workflow can be triggered manually with deploy inputs

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes - v6.0.1

  • Bug Fixes

    • Fixed improper escaping of special characters in saved JSON and NetCDF files
    • Corrected coordinate handling in comparison operations to ensure accurate data representation
  • Documentation

    • Updated documentation workflows for improved deployment processes

@FBumann FBumann marked this pull request as ready for review February 4, 2026 11:30
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

Warning

Rate limit exceeded

@FBumann has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 46 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Introduces two internal helpers to extract and merge non-index coordinates across xarray Datasets, updates concatenation flows (solution, inputs, statistics) to use extraction, concat with coords='minimal', and re-apply merged coordinate mappings to the concatenated result.

Changes

Cohort / File(s) Summary
Comparison coordinate handling
flixopt/comparison.py
Added _extract_nonindex_coords() and _apply_merged_coords() to remove non-index coords from inputs, merge their value mappings, perform xr.concat(..., coords='minimal'), and re-apply merged coords to the concatenated Dataset. Replaced prior direct concat calls in solution, inputs, and statistics paths.
Changelog and IO update
CHANGELOG.md, flixopt/io.py
Added patch release notes ([6.0.1]) and docs/workflow updates. In io.py JSON encoding now uses ensure_ascii=False when dumping JSON to fix escaping in saved artifacts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through datasets, coords all astray,
I scooped up their mappings and showed them the way,
Extract, merge, concat — then gently re-tie,
Now cases align under one friendly sky,
Hooray for tidy coords! 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the three main bug fixes in this patch release: JSON encoding, Comparison coordinates, and documentation warnings.
Description check ✅ Passed The PR description follows the template structure with clear summaries of each bug fix, a comprehensive test plan with checkmarks, and includes all essential information needed to understand the changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/coords-merge-comparison

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 and usage tips.

@FBumann FBumann changed the title Feature/coords merge comparison Fix JSON encoding, Comparison coords, and docs warnings Feb 4, 2026
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
flixopt/comparison.py (1)

309-315: ⚠️ Potential issue | 🟠 Major

Apply coord preservation pattern to solution and inputs properties.

Both solution (line 309) and inputs (line 378) use xr.concat() with coords='minimal', which drops non-index coords (e.g., component on contributor dim). This causes loss of label coordinates that are needed in the combined result.

The helper functions _extract_nonindex_coords() and _apply_merged_coords() already exist and are used successfully in _concat_property() for stats concatenation. Apply the same pattern here:

Suggested pattern
-            self._solution = xr.concat(
-                [ds.expand_dims(case=[name]) for ds, name in zip(datasets, self._names, strict=True)],
-                dim='case',
-                join='outer',
-                coords='minimal',
-                fill_value=float('nan'),
-            )
+            expanded = [ds.expand_dims(case=[name]) for ds, name in zip(datasets, self._names, strict=True)]
+            expanded, merged_coords = _extract_nonindex_coords(expanded)
+            result = xr.concat(expanded, dim='case', join='outer', coords='minimal', fill_value=float('nan'))
+            self._solution = _apply_merged_coords(result, merged_coords)
-            self._inputs = xr.concat(
-                [ds.expand_dims(case=[name]) for ds, name in zip(datasets, self._names, strict=True)],
-                dim='case',
-                join='outer',
-                coords='minimal',
-                fill_value=float('nan'),
-            )
+            expanded = [ds.expand_dims(case=[name]) for ds, name in zip(datasets, self._names, strict=True)]
+            expanded, merged_coords = _extract_nonindex_coords(expanded)
+            result = xr.concat(expanded, dim='case', join='outer', coords='minimal', fill_value=float('nan'))
+            self._inputs = _apply_merged_coords(result, merged_coords)
🤖 Fix all issues with AI agents
In `@flixopt/comparison.py`:
- Around line 58-59: When merging coord mappings in comparison.py, detect
conflicts where the same dim value (dv) already exists in merged[name][1] but
maps to a different coord value (cv); currently the code silently keeps the
first value (merged[name][1][dv] = cv). Modify the logic around the
merged[name][1] assignment to check if dv in merged[name][1] and
merged[name][1][dv] != cv, and then either raise a ValueError (including
identifiers like name, dv, existing value and new cv) or emit a clear warning
(using the project logger) so callers are alerted to inconsistent inputs instead
of silently keeping the first mapping.

- Apply _extract_nonindex_coords pattern to solution and inputs properties
- Add warning when coordinate mappings conflict during merge

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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