Skip to content

Conversation

@Simar-B
Copy link
Contributor

@Simar-B Simar-B commented Jun 13, 2023

Slightly modified _is_dates_only in DatetimeIndex as mentioned in the issue.

@Simar-B Simar-B marked this pull request as ready for review June 13, 2023 19:34
@pmlpm1986
Copy link

I added some remarks about this PR in: #53470

Unfortunately, I do not know much about DatetimeArrays to be to help.

@Simar-B Simar-B closed this Jun 21, 2023
@Simar-B Simar-B reopened this Jun 21, 2023
@Simar-B
Copy link
Contributor Author

Simar-B commented Jun 29, 2023

@topper-123 could you take a look whenever you get the chance?

Copy link
Contributor

@topper-123 topper-123 left a 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.

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")
Copy link
Contributor

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).

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@Simar-B Simar-B requested a review from topper-123 July 4, 2023 15:56
@pmlpm1986
Copy link

@Simar-B, I added some sanity checks of my own in Simar-B#1

Copy link
Contributor

@topper-123 topper-123 left a 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.

@Simar-B Simar-B requested review from mroeschke and topper-123 July 18, 2023 20:52
Copy link
Contributor

@topper-123 topper-123 left a 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.


from pandas.io.formats.format import is_dates_only

delta = self.freq.delta if self.freq and hasattr(self.freq, "delta") else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
delta = self.freq.delta if self.freq and hasattr(self.freq, "delta") else None
delta = getattr(self.freq, "delta", None)
Copy link

@pmlpm1986 pmlpm1986 Jul 20, 2023

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

Copy link
Contributor Author

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.

Simar-B and others added 2 commits July 22, 2023 12:00
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
@mroeschke mroeschke added Datetime Datetime data dtype Output-Formatting __repr__ of pandas objects, to_string labels Jul 22, 2023
@mroeschke mroeschke added this to the 2.1 milestone Jul 22, 2023
@mroeschke mroeschke merged commit 3c01ce2 into pandas-dev:main Jul 22, 2023
@mroeschke
Copy link
Member

Thanks @Simar-B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Datetime Datetime data dtype Output-Formatting __repr__ of pandas objects, to_string

4 participants