Skip to content

BUG: repr of Categorical does not distinguish int and str. #33676

Closed
@simonjayhawkins

Description

@simonjayhawkins
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

>>> pd.Categorical([1, "2", 3, 4])
[1, 2, 3, 4]
Categories (4, object): [1, 3, 4, 2]

Problem description

does not show the string elements quoted. This is inconsistent with numpy.

>>> np.array([1, "2", 3, 4], dtype="object")
array([1, '2', 3, 4], dtype=object)

Expected Output

>>> pd.Categorical([1, "2", 3, 4])
[1, '2', 3, 4]
Categories (4, object): [1, 3, 4, '2']

Output of pd.show_versions()

[paste the output of pd.show_versions() here leaving a blank line after the details tag]

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignBugCategoricalCategorical Data TypeNeeds DiscussionRequires discussion from core team before further actionOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions