Allow optionals with a default value to be exclused from export#149
Open
aglavic wants to merge 3 commits intoreflectivity:mainfrom
Open
Allow optionals with a default value to be exclused from export#149aglavic wants to merge 3 commits intoreflectivity:mainfrom
aglavic wants to merge 3 commits intoreflectivity:mainfrom
Conversation
Contributor
|
Can you provide a simple script for reproducing the problem that this PR addresses? Can it be shown with one of the tests? |
Collaborator
Author
|
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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.