8000 BUG: DTI-datetime_scalar preserve freq by jbrockmendel · Pull Request #48818 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
GH ref
  • Loading branch information
jbrockmendel committed Sep 27, 2022
commit f4d532887e5b11aeee3b883561a2f009f4bf0bd2
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Datetimelike
^^^^^^^^^^^^
- Bug in :func:`pandas.infer_freq`, raising ``TypeError`` when inferred on :class:`RangeIndex` (:issue:`47084`)
- Bug in :class:`DatetimeIndex` constructor failing to raise when ``tz=None`` is explicitly specified in conjunction with timezone-aware ``dtype`` or data (:issue:`48659`)
- Bug in subtracting a ``datetime`` scalar from :class:`DatetimeIndex` failing to retain the original ``freq`` attribute (:issue:`?`)
- Bug in subtracting a ``datetime`` scalar from :class:`DatetimeIndex` failing to retain the original ``freq`` attribute (:issue:`48818`)

Timedelta
^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

class TestDatetimeIndex:
def test_sub_datetime_preserves_reso(self, tz_naive_fixture):
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a test where this goes over a DST transition?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch. when we cross a DST transition, dti.freq is actually wrong bc of the (deprecated) kludge in generate_range. As a result, inheriting the freq is incorrect in this case. But it will return to being correct once the deprecation is enforced.

i think the thing to do is add the test and xfail it

Copy link
Member Author

Choose a reason for hiding this comment

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

test added (and xfailed) + green

# GH#48818
dti = date_range("2016-01-01", periods=12, tz=tz_naive_fixture)

res = dti - dti[0]
Expand Down
0