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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Fixed Regressions
- Fixed regression in ``IntervalDtype`` construction where passing an incorrect string with 'Interval' as a prefix could result in a ``RecursionError``. (:issue:`25338`)
- Fixed regression in :class:`Categorical`, where constructing it from a categorical ``Series`` and an explicit ``categories=`` that differed from that in the ``Series`` created an invalid object which could trigger segfaults. (:issue:`25318`)
- Fixed pip installing from source into an environment without NumPy (:issue:`25193`)
- Fixed name preserving bug of :meth:`DatetimeIndex.snap` (:issue:`25575`)

.. _whatsnew_0242.enhancements:

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,7 @@ def snap(self, freq='S'):
snapped[i] = s

# we know it conforms; skip check
return DatetimeIndex._simple_new(snapped, freq=freq)
# TODO: what about self.name? tz? if so, use shallow_copy?
return DatetimeIndex._simple_new(snapped, name=self.name, freq=freq)

def join(self, other, how='left', level=None, return_indexers=False,
sort=False):
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/series/indexing/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ def test_fancy_setitem():

def test_dti_snap():
dti = DatetimeIndex(['1/1/2002', '1/2/2002', '1/3/2002', '1/4/2002',
'1/5/2002', '1/6/2002', '1/7/2002'], freq='D')
'1/5/2002', '1/6/2002', '1/7/2002'],
name='my_dti', freq='D')

res = dti.snap(freq='W-MON')
exp = date_range('12/31/2001', '1/7/2002', freq='w-mon')
exp = date_range('12/31/2001', '1/7/2002', name='my_dti', freq='w-mon')
exp = exp.repeat([3, 4])
assert (res == exp).all()
assert res.name == exp.name

res = dti.snap(freq='B')

Expand Down