From 3ef30412906f3d897244b5e8175dfa739bc7529c Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 21 Jan 2020 14:56:53 -0800 Subject: [PATCH] BUG: DatetimeIndex.snap incorrectly setting freq --- pandas/core/indexes/datetimes.py | 4 ++-- pandas/tests/series/indexing/test_datetime.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 942b51eda7d0b..134353fe3890c 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -484,8 +484,8 @@ def snap(self, freq="S"): s = t1 snapped[i] = s - # we know it conforms; skip check - return DatetimeIndex._simple_new(snapped, name=self.name, tz=self.tz, freq=freq) + dta = DatetimeArray(snapped, dtype=self.dtype) + return DatetimeIndex._simple_new(dta, name=self.name) def _parsed_string_to_bounds(self, reso, parsed): """ diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index 15ff5f6b343d1..64eb5fa7c8e08 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -73,6 +73,8 @@ def test_dti_snap(name, tz): expected = expected.repeat([3, 4]) tm.assert_index_equal(result, expected) assert result.tz == expected.tz + assert result.freq is None + assert expected.freq is None result = dti.snap(freq="B") @@ -80,6 +82,8 @@ def test_dti_snap(name, tz): expected = expected.repeat([1, 1, 1, 2, 2]) tm.assert_index_equal(result, expected) assert result.tz == expected.tz + assert result.freq is None + assert expected.freq is None def test_dti_reset_index_round_trip():