Skip to content

Commit 846eb70

Browse files
committed
DOC: Fix docs on merging categoricals.
Fixes pandas-dev#28166.
1 parent d91ffa6 commit 846eb70

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

doc/source/user_guide/categorical.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -813,16 +813,16 @@ but the categories of these categoricals need to be the same:
813813
res
814814
res.dtypes
815815
816-
In this case the categories are not the same, and therefore an error is raised:
816+
If the categories are not exactly the same, merging will coerce the
817+
categoricals to their categories' dtypes:
817818

818819
.. ipython:: python
819820
820821
df_different = df.copy()
821822
df_different["cats"].cat.categories = ["c", "d"]
822-
try:
823-
pd.concat([df, df_different])
824-
except ValueError as e:
825-
print("ValueError:", str(e))
823+
res = pd.concat([df, df_different])
824+
res
825+
res.dtypes
826826
827827
The same applies to ``df.append(df_different)``.
828828

doc/source/user_guide/merging.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ The merged result:
883883
.. note::
884884

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

888888
.. note::
889889

0 commit comments

Comments
 (0)