Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

box_from_file returns ruamel.yaml.scalarfloat.ScalarFloat instead of float for floating-point values #264

Open
stellarpower opened this issue Jan 9, 2024 · 1 comment
Labels

Comments

@stellarpower
Copy link

When I load a Box from a YAML file, the floating-pont values are represented as a type from the ruamel YAML library, and not cast to the builtin float type. This resulted in a difficult bug (as without explicitly calling type() on it, it is rendered visually as a float) where these are being improperly serialised when interacting with another library, as it doesn't know how to handle them. This happens even if I convert the box to a builtin dictionary with Box.to_dict().

MRE:

Float: 0.1
import box

float = box.box_from_file('Float.yaml')

print(     float.Float )
print(type(float.Float))

outputs

0.1
<class 'ruamel.yaml.scalarfloat.ScalarFloat'>

I assume it would be more appropriate for all types from YAML/JSON/etc that can be represented as builtin to be converted as part of the process.

I would look into this further, but my debugger seems to refuse to step into the function or hit any manually-added breakpoints - I see .pyi and C wrappers, so looks like it might be implemented internally in C.

Thanks

@stellarpower stellarpower changed the title box_from_file returns 'ruamel.yaml.scalarfloat.ScalarFloat' instead of float for floating-point values box_from_file returns ruamel.yaml.scalarfloat.ScalarFloat instead of float for floating-point values Jan 9, 2024
@stellarpower
Copy link
Author

Assume this may be hanging on this upstream.

@cdgriffith cdgriffith added the bug label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants