Skip to content

Commit f478e30

Browse files
andjhallbgollop
andauthored
TST: Added test for frequency retention in categorical constructor (#46779)
* Added test for github issue #33830 to test that categorical was preserving DateTimeIndex freq attribute * Added an additional test for value_counts preserving frequency * Modified tests in test_constructors.py to pass the pre-commit check * Removed tests from test_constructors that were not needed * Moved categorical freq retention test to pandas/tests/arrays/categorical/ Co-authored-by: Brian Gollop <[email protected]>
1 parent 5b76b77 commit f478e30

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pandas/tests/arrays/categorical/test_constructors.py

+11
Original file line numberDiff line numberDiff line change
@@ -759,3 +759,14 @@ def test_constructor_datetime64_non_nano(self):
759759

760760
cat = Categorical(values, categories=categories)
761761
assert (cat == values).all()
762+
763+
def test_constructor_preserves_freq(self):
764+
# GH33830 freq retention in categorical
765+
dti = date_range("2016-01-01", periods=5)
766+
767+
expected = dti.freq
768+
769+
cat = Categorical(dti)
770+
result = cat.categories.freq
771+
772+
assert expected == result

0 commit comments

Comments
 (0)