Skip to content

Incorrect docs for merging categoricals #28166

Closed
@ivirshup

Description

@ivirshup

The documentation for merging categorical arrays (here) states that calling pd.concat on two data frames with categorical columns will throw an error. This doesn't throw an error, and probably shouldn't following #13767.

Here's the example shown in the docs:

import pandas as pd
cat = pd.Series(["a", "b"], dtype="category")
vals = [1, 2]
df = pd.DataFrame({"cats": cat, "vals": vals})
df_different = df.copy()
df_different["cats"].cat.categories = ["c", "d"]
try:
    pd.concat([df, df_different])
except ValueError as e:
    print("ValueError:", str(e))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions