File tree 3 files changed +11
-1
lines changed
3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -653,6 +653,8 @@ The same applies to ``df.append(df_different)``.
653
653
Unioning
654
654
~~~~~~~~
655
655
656
+ .. versionadded :: 0.18.2
657
+
656
658
If you want to combine categoricals that do not necessarily have
657
659
the same categories, the `union_categorical ` function will
658
660
combine a list-like of categoricals. The new categories
Original file line number Diff line number Diff line change @@ -965,6 +965,9 @@ def test_union_categorical(self):
965
965
with tm .assertRaises (TypeError ):
966
966
union_categoricals ([s , s2 ])
967
967
968
+ with tm .assertRaises (ValueError ):
969
+ union_categoricals ([])
970
+
968
971
def test_concat_bug_1719 (self ):
969
972
ts1 = tm .makeTimeSeries ()
970
973
ts2 = tm .makeTimeSeries ()[::2 ]
Original file line number Diff line number Diff line change @@ -223,13 +223,18 @@ def union_categoricals(to_union):
223
223
TypeError
224
224
If any of the categoricals are ordered or all do not
225
225
have the same dtype
226
+ ValueError
227
+ Emmpty list of categoricals passed
226
228
"""
227
229
from pandas import Index , Categorical
228
230
231
+ if len (to_union ) == 0 :
232
+ raise ValueError ('No Categoricals to union' )
233
+
234
+ first = to_union [0 ]
229
235
if any (c .ordered for c in to_union ):
230
236
raise TypeError ("Can only combine unordered Categoricals" )
231
237
232
- first = to_union [0 ]
233
238
if not all (com .is_dtype_equal (c .categories .dtype , first .categories .dtype )
234
239
for c in to_union ):
235
240
raise TypeError ("dtype of categories must be the same" )
You can’t perform that action at this time.
0 commit comments