Skip to content

Commit 200c336

Browse files
Output formatting: preserve quoting for string categories
1 parent d5eab1b commit 200c336

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pandas/core/arrays/categorical.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2233,8 +2233,14 @@ def _repr_categories(self) -> list[str]:
22332233
)
22342234
from pandas.io.formats import format as fmt
22352235

2236+
formatter = None
2237+
if self.categories.dtype == "str":
2238+
# the extension array formatter defaults to boxed=True in format_array
2239+
# override here to boxed=False to be consistent with QUOTE_NONNUMERIC
2240+
formatter = self.categories._values._formatter(boxed=False)
2241+
22362242
format_array = partial(
2237-
fmt.format_array, formatter=None, quoting=QUOTE_NONNUMERIC
2243+
fmt.format_array, formatter=formatter, quoting=QUOTE_NONNUMERIC
22382244
)
22392245
if len(self.categories) > max_categories:
22402246
num = max_categories // 2

0 commit comments

Comments
 (0)