cdgriffith / cdgriffith/Box

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

Open
#264 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
2.8k
Forks
135
PR merge metrics
No merged PRs in 30d

Description

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:
```YAML
Float: 0.1
```

```python
import box

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

print( float.Float )
print(type(float.Float))
```
outputs
```
0.1

```

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.