Skip to content

nan_to_num fails on object arrays #1125

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
gdementen opened this issue Dec 9, 2024 · 0 comments
Open

nan_to_num fails on object arrays #1125

gdementen opened this issue Dec 9, 2024 · 0 comments

Comments

@gdementen
Copy link
Contributor

Annoyingly, object arrays occur frequently because there is some text in the array when loading it, and in that context something like nan_to_num is often needed.

>>> arr = ndtest((2, 3)).astype(object)
>>> arr['a0', 'b1'] = la.nan
>>> arr
a\b  b0   b1  b2
 a0   0  nan   2
 a1   3    4   5
>>> nan_to_num(arr)
a\b  b0   b1  b2
 a0   0  nan   2
 a1   3    4   5

The workaround is to convert to float:

>>> nan_to_num(arr.astype(float))
a\b   b0   b1   b2
 a0  0.0  0.0  2.0
 a1  3.0  4.0  5.0

I think I remember there was another issue regarding nan and object arrays, but I cannot find it anymore. I guess I fixed that problem without creating an issue about it, because general_isnan and obj_isnan in larray code were created exactly to alleviate this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant