Skip to content

Commit e4b8cbf

Browse files
committed
Added test for github issue pandas-dev#33830 to test that categorical was preserving DateTimeIndex freq attribute
1 parent 8f44244 commit e4b8cbf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pandas/tests/indexes/datetimes/test_constructors.py

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import dateutil
1010
import numpy as np
11+
from pandas._testing.asserters import assert_equal
1112
import pytest
1213
import pytz
1314

@@ -84,6 +85,16 @@ def test_categorical_preserves_tz(self):
8485
result = DatetimeIndex(obj)
8586
tm.assert_index_equal(result, dti)
8687

88+
def test_categorical_preserves_freq(self):
89+
# GH33830 freq retention in categorical
90+
dti = pd.date_range('2016-01-01', periods=5)
91+
expected = dti.freq
92+
93+
cat = pd.Categorical(dti)
94+
result = cat.categories.freq
95+
96+
assert expected == result
97+
8798
def test_dti_with_period_data_raises(self):
8899
# GH#23675
89100
data = pd.PeriodIndex(["2016Q1", "2016Q2"], freq="Q")

0 commit comments

Comments
 (0)