Skip to content

Output formatting: preserve quoting for string categories #61891

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
8 changes: 7 additions & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2233,8 +2233,14 @@ def _repr_categories(self) -> list[str]:
)
from pandas.io.formats import format as fmt

formatter = None
if self.categories.dtype == "str":
# the extension array formatter defaults to boxed=True in format_array
# override here to boxed=False to be consistent with QUOTE_NONNUMERIC
formatter = self.categories._values._formatter(boxed=False)

format_array = partial(
fmt.format_array, formatter=None, quoting=QUOTE_NONNUMERIC
fmt.format_array, formatter=formatter, quoting=QUOTE_NONNUMERIC
)
if len(self.categories) > max_categories:
num = max_categories // 2
Expand Down
Loading