Skip to content

BUG(?): can_hold_element(DTA, np.nan) returns True #53206

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

Closed
mroeschke opened this issue May 12, 2023 · 2 comments
Closed

BUG(?): can_hold_element(DTA, np.nan) returns True #53206

mroeschke opened this issue May 12, 2023 · 2 comments
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type Timestamp pd.Timestamp and associated methods

Comments

@mroeschke
Copy link
Member

mroeschke commented May 12, 2023

In [12]: import pandas as pd

In [13]: import numpy as np

In [14]: arr = pd.arrays.DatetimeArray(np.array([np.datetime64("2020-01-01T00:01:01")]))

In [15]: pd.core.dtypes.cast.can_hold_element(arr, np.nan)
Out[15]: True

I think this is potentially the case for TDA, PeriodArray too.

Is this expected? cc @jbrockmendel

I think this is the crux behind #29024 where this looks buggy

In [17]: pd.Series([pd.NaT]).replace({np.nan: 0})
Out[17]: 
0    0
dtype: int64
@mroeschke mroeschke added Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type Timestamp pd.Timestamp and associated methods labels May 12, 2023
@jbrockmendel
Copy link
Member

This is expected. You can do DTA[0] = np.nan without raising.

@mroeschke
Copy link
Member Author

Cool thanks closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type Timestamp pd.Timestamp and associated methods
Projects
None yet
Development

No branches or pull requests

2 participants