Skip to content

disallow numpy scalars for metadata.fill_value #3025

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

Open
d-v-b opened this issue Apr 28, 2025 · 1 comment
Open

disallow numpy scalars for metadata.fill_value #3025

d-v-b opened this issue Apr 28, 2025 · 1 comment

Comments

@d-v-b
Copy link
Contributor

d-v-b commented Apr 28, 2025

Right now the fill_value attribute of our metadata classes is a numpy scalar, or None, or a string (i think). This is problematic for comparing two metadata instances -- if the fill value is np.nan, then np.nan == np.nan is always false, even when the two values are in fact the same.

We could address this by disallowing numpy scalars for the fill_value attribute. Instead, we could use a custom scalar wrapper class that handles NaN correctly, or use a JSON-serializable form of the scalar, e.g. a string in the case of np.nan.

see also: #2929

@d-v-b
Copy link
Contributor Author

d-v-b commented Apr 29, 2025

an alternative approach: we allow scalars, but we override __eq__ to compare the JSON form of the metadata.

This seems better to me than requiring that the fill_value attribute be JSON-serialized. If we pre-JSONify the fill value, a string array with a fill value that is the string "nan" would falsely appear to have the same fill value as a float array with a np.NaN fill value.

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

No branches or pull requests

1 participant