11import numpy as np
2+ import pytest
3+
4+ from pandas ._config import using_pyarrow_string_dtype
25
36from pandas import (
47 Categorical ,
58 CategoricalDtype ,
69 CategoricalIndex ,
10+ Index ,
711 Series ,
812 date_range ,
913 option_context ,
1317
1418
1519class TestCategoricalReprWithFactor :
16- def test_print (self , factor ):
17- expected = [
18- "['a', 'b', 'b', 'a', 'a', 'c', 'c', 'c']" ,
19- "Categories (3, object): ['a' < 'b' < 'c']" ,
20- ]
20+ def test_print (self , factor , using_infer_string ):
21+ if using_infer_string :
22+ expected = [
23+ "['a', 'b', 'b', 'a', 'a', 'c', 'c', 'c']" ,
24+ "Categories (3, string): [a < b < c]" ,
25+ ]
26+ else :
27+ expected = [
28+ "['a', 'b', 'b', 'a', 'a', 'c', 'c', 'c']" ,
29+ "Categories (3, object): ['a' < 'b' < 'c']" ,
30+ ]
2131 expected = "\n " .join (expected )
2232 actual = repr (factor )
2333 assert actual == expected
@@ -26,7 +36,7 @@ def test_print(self, factor):
2636class TestCategoricalRepr :
2737 def test_big_print (self ):
2838 codes = np .array ([0 , 1 , 2 , 0 , 1 , 2 ] * 100 )
29- dtype = CategoricalDtype (categories = ["a" , "b" , "c" ])
39+ dtype = CategoricalDtype (categories = Index ( ["a" , "b" , "c" ], dtype = object ) )
3040 factor = Categorical .from_codes (codes , dtype = dtype )
3141 expected = [
3242 "['a', 'b', 'c', 'a', 'b', ..., 'b', 'c', 'a', 'b', 'c']" ,
@@ -40,13 +50,13 @@ def test_big_print(self):
4050 assert actual == expected
4151
4252 def test_empty_print (self ):
43- factor = Categorical ([], ["a" , "b" , "c" ])
53+ factor = Categorical ([], Index ( ["a" , "b" , "c" ], dtype = object ) )
4454 expected = "[], Categories (3, object): ['a', 'b', 'c']"
4555 actual = repr (factor )
4656 assert actual == expected
4757
4858 assert expected == actual
49- factor = Categorical ([], ["a" , "b" , "c" ], ordered = True )
59+ factor = Categorical ([], Index ( ["a" , "b" , "c" ], dtype = object ) , ordered = True )
5060 expected = "[], Categories (3, object): ['a' < 'b' < 'c']"
5161 actual = repr (factor )
5262 assert expected == actual
@@ -66,6 +76,10 @@ def test_print_none_width(self):
6676 with option_context ("display.width" , None ):
6777 assert exp == repr (a )
6878
79+ @pytest .mark .skipif (
80+ using_pyarrow_string_dtype (),
81+ reason = "Change once infer_string is set to True by default" ,
82+ )
6983 def test_unicode_print (self ):
7084 c = Categorical (["aaaaa" , "bb" , "cccc" ] * 20 )
7185 expected = """\
0 commit comments