10
10
from pandas import CategoricalIndex
11
11
12
12
13
- class TestCategoricalIndexRepr :
14
- @pytest .mark .xfail (using_string_dtype (), reason = "repr different" )
15
- def test_string_categorical_index_repr (self ):
13
+ class TestCategoricalIndexReprStringCategories :
14
+ def test_string_categorical_index_repr (self , using_infer_string ):
16
15
# short
17
16
idx = CategoricalIndex (["a" , "bb" , "ccc" ])
18
17
expected = """CategoricalIndex(['a', 'bb', 'ccc'], categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa: E501
18
+ if using_infer_string :
19
+ expected = expected .replace (
20
+ "categories=['a', 'bb', 'ccc']" ,
21
+ "categories=[a, bb, ccc]" ,
22
+ )
19
23
assert repr (idx ) == expected
20
24
25
+ @pytest .mark .xfail (using_string_dtype (), reason = "Different padding on multi-line" )
26
+ def test_categorical_index_repr_multiline (self , using_infer_string ):
21
27
# multiple lines
22
28
idx = CategoricalIndex (["a" , "bb" , "ccc" ] * 10 )
23
29
expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',
24
30
'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb',
25
31
'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],
26
32
categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa: E501
27
-
33
+ if using_infer_string :
34
+ expected = expected .replace (
35
+ "categories=['a', 'bb', 'ccc']" ,
36
+ "categories=[a, bb, ccc]" ,
37
+ )
28
38
assert repr (idx ) == expected
29
39
40
+ @pytest .mark .xfail (using_string_dtype (), reason = "Different padding on multi-line" )
41
+ def test_categorical_index_repr_truncated (self , using_infer_string ):
30
42
# truncated
31
43
idx = CategoricalIndex (["a" , "bb" , "ccc" ] * 100 )
32
44
expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',
33
45
...
34
46
'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],
35
47
categories=['a', 'bb', 'ccc'], ordered=False, dtype='category', length=300)""" # noqa: E501
36
-
48
+ if using_infer_string :
49
+ expected = expected .replace (
50
+ "categories=['a', 'bb', 'ccc']" ,
51
+ "categories=[a, bb, ccc]" ,
52
+ )
37
53
assert repr (idx ) == expected
38
54
55
+ def test_categorical_index_repr_many_categories (self , using_infer_string ):
39
56
# larger categories
40
57
idx = CategoricalIndex (list ("abcdefghijklmmo" ))
41
58
expected = """CategoricalIndex(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
42
59
'm', 'm', 'o'],
43
60
categories=['a', 'b', 'c', 'd', ..., 'k', 'l', 'm', 'o'], ordered=False, dtype='category')""" # noqa: E501
44
-
61
+ if using_infer_string :
62
+ expected = expected .replace (
63
+ "categories=['a', 'b', 'c', 'd', ..., 'k', 'l', 'm', 'o']" ,
64
+ "categories=[a, b, c, d, ..., k, l, m, o]" ,
65
+ )
45
66
assert repr (idx ) == expected
46
67
68
+ def test_categorical_index_repr_unicode (self , using_infer_string ):
47
69
# short
48
70
idx = CategoricalIndex (["あ" , "いい" , "ううう" ])
49
71
expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
72
+ if using_infer_string :
73
+ expected = expected .replace (
74
+ "categories=['あ', 'いい', 'ううう']" ,
75
+ "categories=[あ, いい, ううう]" ,
76
+ )
50
77
assert repr (idx ) == expected
51
78
79
+ @pytest .mark .xfail (using_string_dtype (), reason = "Different padding on multi-line" )
80
+ def test_categorical_index_repr_unicode_multiline (self , using_infer_string ):
52
81
# multiple lines
53
82
idx = CategoricalIndex (["あ" , "いい" , "ううう" ] * 10 )
54
83
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
55
84
'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
56
85
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
57
86
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
58
-
87
+ if using_infer_string :
88
+ expected = expected .replace (
89
+ "categories=['あ', 'いい', 'ううう']" ,
90
+ "categories=[あ, いい, ううう]" ,
91
+ )
59
92
assert repr (idx ) == expected
60
93
94
+ @pytest .mark .xfail (using_string_dtype (), reason = "Different padding on multi-line" )
95
+ def test_categorical_index_repr_unicode_truncated (self , using_infer_string ):
61
96
# truncated
62
97
idx = CategoricalIndex (["あ" , "いい" , "ううう" ] * 100 )
63
98
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
64
99
...
65
100
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
66
101
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa: E501
67
-
102
+ if using_infer_string :
103
+ expected = expected .replace (
104
+ "categories=['あ', 'いい', 'ううう']" ,
105
+ "categories=[あ, いい, ううう]" ,
106
+ )
68
107
assert repr (idx ) == expected
69
108
109
+ def test_categorical_index_repr_unicode_many_categories (self , using_infer_string ):
70
110
# larger categories
71
111
idx = CategoricalIndex (list ("あいうえおかきくけこさしすせそ" ))
72
112
expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', 'さ', 'し',
73
113
'す', 'せ', 'そ'],
74
114
categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ'], ordered=False, dtype='category')""" # noqa: E501
75
-
115
+ if using_infer_string :
116
+ expected = expected .replace (
117
+ "categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ']" ,
118
+ "categories=[あ, い, う, え, ..., し, す, せ, そ]" ,
119
+ )
76
120
assert repr (idx ) == expected
77
121
78
- # Enable Unicode option -----------------------------------------
122
+ def test_categorical_index_repr_east_asian_width ( self , using_infer_string ):
79
123
with cf .option_context ("display.unicode.east_asian_width" , True ):
80
124
# short
81
125
idx = CategoricalIndex (["あ" , "いい" , "ううう" ])
82
126
expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
127
+ if using_infer_string :
128
+ expected = expected .replace (
129
+ "categories=['あ', 'いい', 'ううう']" ,
130
+ "categories=[あ, いい, ううう]" ,
131
+ )
83
132
assert repr (idx ) == expected
84
133
134
+ @pytest .mark .xfail (using_string_dtype (), reason = "Different padding on multi-line" )
135
+ def test_categorical_index_repr_east_asian_width_multiline (
136
+ self , using_infer_string
137
+ ):
138
+ with cf .option_context ("display.unicode.east_asian_width" , True ):
85
139
# multiple lines
86
140
idx = CategoricalIndex (["あ" , "いい" , "ううう" ] * 10 )
87
141
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
@@ -90,8 +144,18 @@ def test_string_categorical_index_repr(self):
90
144
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
91
145
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
92
146
147
+ if using_infer_string :
148
+ expected = expected .replace (
149
+ "categories=['あ', 'いい', 'ううう']" ,
150
+ "categories=[あ, いい, ううう]" ,
151
+ )
93
152
assert repr (idx ) == expected
94
153
154
+ @pytest .mark .xfail (using_string_dtype (), reason = "Different padding on multi-line" )
155
+ def test_categorical_index_repr_east_asian_width_truncated (
156
+ self , using_infer_string
157
+ ):
158
+ with cf .option_context ("display.unicode.east_asian_width" , True ):
95
159
# truncated
96
160
idx = CategoricalIndex (["あ" , "いい" , "ううう" ] * 100 )
97
161
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
@@ -101,12 +165,25 @@ def test_string_categorical_index_repr(self):
101
165
'あ', 'いい', 'ううう'],
102
166
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa: E501
103
167
168
+ if using_infer_string :
169
+ expected = expected .replace (
170
+ "categories=['あ', 'いい', 'ううう']" ,
171
+ "categories=[あ, いい, ううう]" ,
172
+ )
104
173
assert repr (idx ) == expected
105
174
106
- # larger categories
175
+ def test_categorical_index_repr_east_asian_width_many_categories (
176
+ self , using_infer_string
177
+ ):
178
+ with cf .option_context ("display.unicode.east_asian_width" , True ):
107
179
idx = CategoricalIndex (list ("あいうえおかきくけこさしすせそ" ))
108
180
expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ',
109
181
'さ', 'し', 'す', 'せ', 'そ'],
110
182
categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ'], ordered=False, dtype='category')""" # noqa: E501
111
183
184
+ if using_infer_string :
185
+ expected = expected .replace (
186
+ "categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ']" ,
187
+ "categories=[あ, い, う, え, ..., し, す, せ, そ]" ,
188
+ )
112
189
assert repr (idx ) == expected
0 commit comments