Skip to content

Add JSON save/load support alongside TOML#1259

Merged
raphaeltimbo merged 1 commit intopetrobras:mainfrom
raphaeltimbo:add-json-save-load
Feb 13, 2026
Merged

Add JSON save/load support alongside TOML#1259
raphaeltimbo merged 1 commit intopetrobras:mainfrom
raphaeltimbo:add-json-save-load

Conversation

@raphaeltimbo
Copy link
Collaborator

Summary

  • Add format-aware I/O helpers (load_data, dump_data, dump_data_numpy) to ross/utils.py that detect file format from the extension (.toml or .json)
  • Replace direct toml.load/toml.dump calls across all element, rotor, and results save/load methods with the new helpers
  • Add NumpyEncoder for JSON serialization of numpy types, with graceful handling of non-serializable objects

Test plan

  • All existing TOML save/load tests pass (no regressions)
  • New JSON round-trip tests added for: DiskElement, ShaftElement, CouplingElement, BearingElement, PointMass, Rotor, CampbellResults, ForcedResponseResults
  • Verify CI passes

Add format-aware I/O helpers (load_data, dump_data, dump_data_numpy)
to ross/utils.py that detect file format from the extension. All
save/load methods across elements, rotor assembly, results, and
stochastic results now support both .toml and .json files.

- Add NumpyEncoder for JSON serialization of numpy types
- Replace direct toml.load/toml.dump calls with format-aware helpers
- Handle non-serializable objects (callables, Rotor) gracefully
- Use json.dumps before writing to prevent partial file corruption
- Add JSON round-trip tests for all element types, rotor, and results
@raphaeltimbo raphaeltimbo merged commit a71eded into petrobras:main Feb 13, 2026
9 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