I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
import pandas as pd import numpy as np x1 = pd.Series([1, 2, None, 4]) x2 = pd.Series([1, 2, np.nan, 4]) x3 = pd.Series([1, 2, pd.NA, 4]) print(x1.to_numpy('int32', na_value=0)) # [1 2 0 4] print(x2.to_numpy('int32', na_value=0)) # [1 2 0 4] print(x3.to_numpy('int32', na_value=0)) # Traceback (most recent call last): # File "<input>", line 14, in <module> # print(x3.to_numpy('int32', na_value=0)) # File "C:\src\venv\w310\lib\site-packages\pandas\core\base.py", line 535, in to_numpy # result = np.asarray(self._values, dtype=dtype) # TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NAType' print(x3.to_numpy('float64', na_value=0)) # Traceback (most recent call last): # File "<input>", line 22, in <module> # print(x3.to_numpy('float64', na_value=0)) # File "C:\src\venv\w310\lib\site-packages\pandas\core\base.py", line 535, in to_numpy # result = np.asarray(self._values, dtype=dtype) # TypeError: float() argument must be a string or a real number, not 'NAType'Issue Description
It appears that a Series that has a missing value that was created using either None
or np.nan
can be replaced by using Series.to_numpy(dtype=, na_value=)
, but one created with pd.NA
fails with a raised exception (both arguments must be specified to trigger the behavior).
It is expected that since all three values (None
, np.nan
, and pd.NA
) all represent missing values, that all three should behave the same. For the above reproducible example, the print statements should all report [1 2 0 4]
(or [1. 2. 0. 4.]
for the fourth 'float64' case).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4