-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: fix datetimeindex repr #53634
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
BUG: fix datetimeindex repr #53634
Conversation
I added some remarks about this PR in: #53470 Unfortunately, I do not know much about DatetimeArrays to be to help. |
@topper-123 could you take a look whenever you get the chance? |
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.
Thanks for looking into this.
Looks good generally, a question about the heuristics for finding non-day-based indexes.
@@ -196,3 +196,17 @@ def test_asarray_tz_aware(self): | |||
result = np.asarray(idx, dtype=object) | |||
|
|||
tm.assert_numpy_array_equal(result, expected) | |||
|
|||
def test__is_dates_only_freq_less_than_day(self): | |||
idx = DatetimeIndex(["2012-01-01 00:00:00"], freq=str(60) + "T") |
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.
add gh number as first line for each test (# GH53634
).
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_dates_only
is an internal property, so shouldn't be tested. Can you test that the result from repr(idx)
is correct instead.
Also can you move the test to pandas/tests/indexes/datetimes/test_formats.py::TestDatetimeIndexRendering::test_dti_repr_short
.
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.
Could you explain a bit on how the tests at pandas/tests/indexes/datetimes/test_formats.py::TestDatetimeIndexRendering::test_dti_repr_short
work? There's no assertion so I'm not sure how they evaluate to a pass or a fail.
…o bug-fix-datetimeindex
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.
A few comments still, looks close.
…o bug-fix-datetimeindex
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.
LGTM. I'll wait for the response from @mroeschke if he has additional comments.
pandas/core/indexes/datetimes.py
Outdated
from pandas.io.formats.format import is_dates_only | ||
|
||
delta = self.freq.delta if self.freq and hasattr(self.freq, "delta") else 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.
delta = self.freq.delta if self.freq and hasattr(self.freq, "delta") else None | |
delta = getattr(self.freq, "delta", 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.
There seem to be no tests for non-daily and non-hourly freq values. I provided a more comprehensive set of tests in Simar-B#1
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.
Unfortunately right now it is impossible to differentiate a DatetimeIndex
where time has been passed vs when time has not been passed (see here). Therefore, nothing more can be done afaik.
Co-authored-by: Matthew Roeschke <[email protected]>
Thanks @Simar-B |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Slightly modified
_is_dates_only
inDatetimeIndex
as mentioned in the issue.