File tree 2 files changed +6
-6
lines changed
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:
813
813
res
814
814
res.dtypes
815
815
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:
817
818
818
819
.. ipython :: python
819
820
820
821
df_different = df.copy()
821
822
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
826
826
827
827
The same applies to ``df.append(df_different) ``.
828
828
Original file line number Diff line number Diff line change @@ -883,7 +883,7 @@ The merged result:
883
883
.. note ::
884
884
885
885
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.
887
887
888
888
.. note ::
889
889
You can’t perform that action at this time.
0 commit comments