Skip to content

BUG: fix padding for string categories in CategoricalIndex repr #61894

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
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ def _format_data(self, name=None) -> str_t:
is_justify = False
elif isinstance(self.dtype, CategoricalDtype):
self = cast("CategoricalIndex", self)
if is_object_dtype(self.categories.dtype):
if is_string_dtype(self.categories.dtype):
is_justify = False
elif isinstance(self, ABCRangeIndex):
# We will do the relevant formatting via attrs
Expand Down
9 changes: 0 additions & 9 deletions pandas/tests/indexes/categorical/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
Tests for CategoricalIndex.__repr__ and related methods.
"""

import pytest

from pandas._config import using_string_dtype
import pandas._config.config as cf

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

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

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

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

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

@pytest.mark.xfail(using_string_dtype(), reason="Different padding on multi-line")
def test_categorical_index_repr_east_asian_width_multiline(
self, using_infer_string
):
Expand All @@ -151,7 +143,6 @@ def test_categorical_index_repr_east_asian_width_multiline(
)
assert repr(idx) == expected

@pytest.mark.xfail(using_string_dtype(), reason="Different padding on multi-line")
def test_categorical_index_repr_east_asian_width_truncated(
self, using_infer_string
):
Expand Down
Loading