Skip to content

BUG: DatetimeArray/Series incorrectly accepts timedelta64('NaT') for __setitem__ #27297

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
jbrockmendel opened this issue Jul 8, 2019 · 3 comments · Fixed by #27311
Closed
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type
Milestone

Comments

@jbrockmendel
Copy link
Member

dti = pd.date_range('2016-01-01', periods=3)
nat = np.timedelta64('NaT')

dta = dti._data.copy()
dta[0] = nat  # <-- should raise TypeError, doesn't

ser = pd.Series(dti.copy())
ser[1] = nat  # <-- should raise TypeError, doesn't

df = pd.DataFrame(dti.copy())
df.loc[2, 0] = nat  # <-- should raise TypeError, doesn't

I haven't checked, but I expect the same thing happens in reverse for Timedelta, possible Period dtypes.

@jbrockmendel
Copy link
Member Author

"should" behavior in OP is wrong, it should cast to object dtype, but does does not

@jreback jreback added Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type labels Jul 22, 2019
@jreback jreback added this to the 1.0 milestone Jul 22, 2019
@jbrockmendel
Copy link
Member Author

I think I incorrectly marked #27311 as closing this, while that only fixes the Series portion of this. I still need to fix the DTA version.

@jbrockmendel jbrockmendel reopened this Jul 22, 2019
@jbrockmendel
Copy link
Member Author

Woops, #27331 does fix the other half of this.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants