Skip to content

Commit

Permalink
DOC: Fix docs on merging categoricals.
Browse files Browse the repository at this point in the history
Fixes #28166.
  • Loading branch information
ivirshup committed Oct 7, 2019
1 parent af498fe commit 1b9bb12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions doc/source/user_guide/categorical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -813,16 +813,16 @@ but the categories of these categoricals need to be the same:
res
res.dtypes
In this case the categories are not the same, and therefore an error is raised:
If the categories are not exactly the same, merging will coerce the
categoricals to their categories' dtypes:

.. ipython:: python
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))
res = pd.concat([df, df_different])
res
res.dtypes
The same applies to ``df.append(df_different)``.

Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/merging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ The merged result:
.. note::

The category dtypes must be *exactly* the same, meaning the same categories and the ordered attribute.
Otherwise the result will coerce to ``object`` dtype.
Otherwise the result will coerce to the categories' dtype.

.. note::

Expand Down

0 comments on commit 1b9bb12

Please sign in to comment.