Skip to content

TST: Added test for frequency retention in categorical constructor #46779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 18, 2022
Merged
Changes from 4 commits
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
12 changes: 12 additions & 0 deletions pandas/tests/indexes/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
to_datetime,
)
import pandas._testing as tm
from pandas._testing.asserters import assert_equal
from pandas.core.arrays import (
DatetimeArray,
period_array,
Expand Down Expand Up @@ -84,6 +85,17 @@ def test_categorical_preserves_tz(self):
result = DatetimeIndex(obj)
tm.assert_index_equal(result, dti)

def test_categorical_preserves_freq(self):
# GH33830 freq retention in categorical
dti = date_range("2016-01-01", periods=5)

expected = dti.freq

cat = pd.Categorical(dti)
result = cat.categories.freq

assert_equal(expected, result)

def test_dti_with_period_data_raises(self):
# GH#23675
data = pd.PeriodIndex(["2016Q1", "2016Q2"], freq="Q")
Expand Down