You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From #26848. When you pass a ndarray to the DataFrame constructor and specify a dtype, this does a "plain" numpy astype, which can have some unwanted side-effects (that we avoid in other parts of pandas) such as np.nan -> integer conversion and out of bounds timestamps:
In [29]: pd.DataFrame(np.array([[1, np.nan], [2, 3]])).astype(dtype='int64')
...
~/scipy/pandas/pandas/core/dtypes/cast.py in astype_nansafe(arr, dtype, copy, skipna)
678
679 if not np.isfinite(arr).all():
--> 680 raise ValueError('Cannot convert non-finite values (NA or inf) to '
681 'integer')
682
ValueError: Cannot convert non-finite values (NA or inf) to integer
In [30]: pd.DataFrame(np.array([['2300-01-01']], dtype='datetime64[D]')).astype(dtype='datetime64[ns]')
...
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 2300-01-01 00:00:00
I suppose we want to do such a safe astype in DataFrame constructor itself as well?
The text was updated successfully, but these errors were encountered:
From #26848. When you pass a ndarray to the DataFrame constructor and specify a dtype, this does a "plain" numpy
astype
, which can have some unwanted side-effects (that we avoid in other parts of pandas) such as np.nan -> integer conversion and out of bounds timestamps:Both cases are guarded in DataFrame.astype:
I suppose we want to do such a safe astype in DataFrame constructor itself as well?
The text was updated successfully, but these errors were encountered: