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

BUG: np.nan converts to np.int64 without error. #22076

Closed
Micky774 opened this issue Aug 2, 2022 · 1 comment
Closed

BUG: np.nan converts to np.int64 without error. #22076

Micky774 opened this issue Aug 2, 2022 · 1 comment
Labels

Comments

@Micky774
Copy link
Contributor

Micky774 commented Aug 2, 2022

Describe the issue:

Currently np.array([np.nan], dtype=np.int64) raises an error, however np.array([np.nan]).astype(np.int64) is undefined behavior that only issues a warning. Would it be worth promoting this to an error to stay consistent with np.array behavior?

Reproduce the code example:

import numpy as np

np.array([np.nan]).astype(np.int64) # Works while issuing 'invalid value' warning

np.array([np.nan], dtype=np.int64) # Raises 'ValueError: cannot convert float NaN to integer'

Error message:

No response

NumPy/Python version information:

1.24.0.dev0+578.g918065167 3.9.12 (main, Jun  1 2022, 11:38:51) 
[GCC 7.5.0]
@seberg
Copy link
Member

seberg commented Aug 3, 2022

PR that introduced warnings is gh-21437 a duplicate of this that I did not close is gh-14412

@Micky774 Micky774 closed this as completed Aug 3, 2022
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