-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: repr of np.datetime64('NaT') in Series/DataFrame with dtype object #25445
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
Changes from 3 commits
7b32412
83ec1de
e67403e
b7aaa02
4f6e772
645c828
7dcc823
ca7a257
2ab9f14
8d8abd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
from pandas._libs import lib | ||
from pandas._libs.tslib import format_array_from_datetime | ||
from pandas._libs.tslibs import NaT, Timedelta, Timestamp, iNaT | ||
from pandas._libs.tslibs.nattype import is_np_nat | ||
from pandas.compat import StringIO, lzip, map, u, zip | ||
|
||
from pandas.core.dtypes.common import ( | ||
|
@@ -946,7 +947,7 @@ def _format(x): | |
if self.na_rep is not None and is_scalar(x) and isna(x): | ||
if x is None: | ||
return 'None' | ||
elif x is NaT: | ||
elif x is NaT or is_np_nat(x): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use is_null_datetimelike instead of rolling your own There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want yet another NaT detection routine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return 'NaT' | ||
return self.na_rep | ||
elif isinstance(x, PandasObject): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -521,3 +521,11 @@ def test_repr_categorical_dates_periods(self): | |
|
||
df = DataFrame({'dt': Categorical(dt), 'p': Categorical(p)}) | ||
assert repr(df) == exp | ||
|
||
@pytest.mark.parametrize('arg', [np.datetime64, np.timedelta64]) | ||
@pytest.mark.parametrize('box, expected', [ | ||
[Series, '0 NaT\ndtype: object'], | ||
[DataFrame, ' 0\n0 NaT']]) | ||
def test_repr_np_nat_with_object(self, arg, box, expected): | ||
result = repr(box([arg('NaT')], dtype=object)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add the issue number |
||
assert result == expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be removed