Skip to content

Allow optionals with a default value to be exclused from export#149

Open
aglavic wants to merge 3 commits intoreflectivity:mainfrom
aglavic:minor_fixes
Open

Allow optionals with a default value to be exclused from export#149
aglavic wants to merge 3 commits intoreflectivity:mainfrom
aglavic:minor_fixes

Conversation

@aglavic
Copy link
Collaborator

@aglavic aglavic commented Feb 13, 2026

Make the output YAML more concise by removing optional arguments not only when they are None but also when they have the default value. The particular application is in the model language wher the global ModelParameters always prints all value, even if the user just wanted to overwrite a single one.

@bmaranville
Copy link
Contributor

Can you provide a simple script for reproducing the problem that this PR addresses? Can it be shown with one of the tests?

@aglavic
Copy link
Collaborator Author

aglavic commented Mar 12, 2026

Thanks @bmaranville, good point. This way I already found a bug that this was only done in to_dict, not in to_yaml. I've now added a testcase.

Just to illustrate, if you run the following:

from orsopy.fileio import model_language as ml
import yaml
print(ml.ModelParameters.from_dict(yaml.safe_load('roughness: {magnitude: 0.7, unit: nm}')).to_yaml())

The output before would be:

roughness: {magnitude: 0.7, unit: nm}
length_unit: nm
mass_density_unit: g/cm^3
number_density_unit: 1/nm^3
sld_unit: 1/angstrom^2
magnetic_moment_unit: muB
slice_resolution: {magnitude: 1.0, unit: nm}
default_solvent:
  formula: H2O
  mass_density: {magnitude: 1.0, unit: g/cm^3}

And now is:

roughness: {magnitude: 0.7, unit: nm}

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.

2 participants