Skip to content

BUG: numpy.datetime('NaT') printing inconsistency #11220

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
kawochen opened this issue Oct 2, 2015 · 2 comments · Fixed by #30222
Closed

BUG: numpy.datetime('NaT') printing inconsistency #11220

kawochen opened this issue Oct 2, 2015 · 2 comments · Fixed by #30222
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@kawochen
Copy link
Contributor

kawochen commented Oct 2, 2015

Whether np.datetime64('NaT') is printed as NaT or NaN depends on other types present in the column. This is consistent with pd.NaT, whose display also depends on other types. But when all the other scalars are None, pd.NaT and None are both printed as NaT, whereas in a column of np.datetime64('NaT') and None, it depends on the order of the entries (last two lines).

In [44]: pd.DataFrame([[np.datetime64('NaT')], [None]])
Out[44]:
      0
0   NaN
1  None

In [45]: pd.DataFrame([[pd.NaT], [None]])
Out[45]:
    0
0 NaT
1 NaT

In [46]: pd.DataFrame([[np.datetime64('NaT')], [pd.NaT]])
Out[46]:
    0
0 NaT
1 NaT

In [47]: pd.DataFrame([[pd.NaT], [np.datetime64('NaT')]])
Out[47]:
    0
0 NaT
1 NaT

In [81]: pd.DataFrame([[None],[np.datetime64('NaT')]])
Out[81]:
    0
0 NaT
1 NaT

In [82]: pd.DataFrame([[np.datetime64('NaT')],[None]])
Out[82]:
      0
0   NaN
1  None

In [86]: pd.DataFrame([[None],[np.datetime64('NaT')]]).dtypes
Out[86]:
0    datetime64[ns]
dtype: object

In [87]: pd.DataFrame([[np.datetime64('NaT')],[None]]).dtypes
Out[87]:
0    object
dtype: object
@jreback jreback added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Output-Formatting __repr__ of pandas objects, to_string labels Oct 2, 2015
@jreback
Copy link
Contributor

jreback commented Oct 2, 2015

yeh these are coercion issues actually, e.g. in infer.pyx, the np.datetime64('NaT') is not recognized like NaT,None,NaN (IOW it should trigger the conversions like what NaT does

@mroeschke
Copy link
Member

Looks like np.datetime('NaT') is getting correctly recognized as datetime64ns now. Could use a test.

In [137]: In [44]: pd.DataFrame([[np.datetime64('NaT')], [None]])
     ...:
Out[137]:
    0
0 NaT
1 NaT

In [138]: pd.__version__
Out[138]: '0.26.0.dev0+576.gde67bb72e'

@mroeschke mroeschke added good first issue Needs Info Clarification about behavior needed to assess issue Needs Tests Unit test(s) needed to prevent regressions and removed Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Output-Formatting __repr__ of pandas objects, to_string Needs Info Clarification about behavior needed to assess issue labels Oct 16, 2019
@jbrockmendel jbrockmendel added the Output-Formatting __repr__ of pandas objects, to_string label Oct 16, 2019
@jreback jreback added this to the 1.1 milestone Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants