File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments