-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25445 +/- ##
==========================================
+ Coverage 91.74% 91.74% +<.01%
==========================================
Files 173 173
Lines 52923 52924 +1
==========================================
+ Hits 48554 48556 +2
+ Misses 4369 4368 -1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25445 +/- ##
==========================================
+ Coverage 91.77% 91.79% +0.01%
==========================================
Files 175 174 -1
Lines 52606 52539 -67
==========================================
- Hits 48280 48229 -51
+ Misses 4326 4310 -16
Continue to review full report at Codecov.
|
pandas/io/formats/format.py
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
is_null_datetimelike
is too permissive here (accepts np.nan
and None
)
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.
I don't want yet another NaT detection routine.
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.
is_null_datetimelike
doesn't just detect NaT though. It checks if any args are None, np.nan, NaT, iNaT
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.
see comment
cf7f51a
to
b7aaa02
Compare
pandas/io/formats/format.py
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want yet another NaT detection routine.
let's wait till we merge the min numpy 1.13 and then revist |
pandas/io/formats/format.py
Outdated
@@ -14,6 +14,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 |
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
return 'None' | ||
elif x is NaT: | ||
return 'NaT' | ||
try: |
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.
can you add a comment here on what is going on here
[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 comment
The reason will be displayed to describe this comment to others. Learn more.
can you add the issue number
Address comments and all green |
thanks @mroeschke |
git diff upstream/master -u -- "*.py" | flake8 --diff
Discovered while investigating #12499
Before:
After: