Skip to content

Commit 8de38e8

Browse files
BUG: fix padding for string categories in CategoricalIndex repr (#61894)
1 parent 6a6a1ba commit 8de38e8

File tree

2 files changed

+1
-10
lines changed

2 files changed

+1
-10
lines changed

pandas/core/indexes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ def _format_data(self, name=None) -> str_t:
14151415
is_justify = False
14161416
elif isinstance(self.dtype, CategoricalDtype):
14171417
self = cast("CategoricalIndex", self)
1418-
if is_object_dtype(self.categories.dtype):
1418+
if is_string_dtype(self.categories.dtype):
14191419
is_justify = False
14201420
elif isinstance(self, ABCRangeIndex):
14211421
# We will do the relevant formatting via attrs

pandas/tests/indexes/categorical/test_formats.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
Tests for CategoricalIndex.__repr__ and related methods.
33
"""
44

5-
import pytest
6-
7-
from pandas._config import using_string_dtype
85
import pandas._config.config as cf
96

107
from pandas import CategoricalIndex
@@ -22,7 +19,6 @@ def test_string_categorical_index_repr(self, using_infer_string):
2219
)
2320
assert repr(idx) == expected
2421

25-
@pytest.mark.xfail(using_string_dtype(), reason="Different padding on multi-line")
2622
def test_categorical_index_repr_multiline(self, using_infer_string):
2723
# multiple lines
2824
idx = CategoricalIndex(["a", "bb", "ccc"] * 10)
@@ -37,7 +33,6 @@ def test_categorical_index_repr_multiline(self, using_infer_string):
3733
)
3834
assert repr(idx) == expected
3935

40-
@pytest.mark.xfail(using_string_dtype(), reason="Different padding on multi-line")
4136
def test_categorical_index_repr_truncated(self, using_infer_string):
4237
# truncated
4338
idx = CategoricalIndex(["a", "bb", "ccc"] * 100)
@@ -76,7 +71,6 @@ def test_categorical_index_repr_unicode(self, using_infer_string):
7671
)
7772
assert repr(idx) == expected
7873

79-
@pytest.mark.xfail(using_string_dtype(), reason="Different padding on multi-line")
8074
def test_categorical_index_repr_unicode_multiline(self, using_infer_string):
8175
# multiple lines
8276
idx = CategoricalIndex(["あ", "いい", "ううう"] * 10)
@@ -91,7 +85,6 @@ def test_categorical_index_repr_unicode_multiline(self, using_infer_string):
9185
)
9286
assert repr(idx) == expected
9387

94-
@pytest.mark.xfail(using_string_dtype(), reason="Different padding on multi-line")
9588
def test_categorical_index_repr_unicode_truncated(self, using_infer_string):
9689
# truncated
9790
idx = CategoricalIndex(["あ", "いい", "ううう"] * 100)
@@ -131,7 +124,6 @@ def test_categorical_index_repr_east_asian_width(self, using_infer_string):
131124
)
132125
assert repr(idx) == expected
133126

134-
@pytest.mark.xfail(using_string_dtype(), reason="Different padding on multi-line")
135127
def test_categorical_index_repr_east_asian_width_multiline(
136128
self, using_infer_string
137129
):
@@ -151,7 +143,6 @@ def test_categorical_index_repr_east_asian_width_multiline(
151143
)
152144
assert repr(idx) == expected
153145

154-
@pytest.mark.xfail(using_string_dtype(), reason="Different padding on multi-line")
155146
def test_categorical_index_repr_east_asian_width_truncated(
156147
self, using_infer_string
157148
):

0 commit comments

Comments
 (0)