Skip to content

Commit 568784f

Browse files
committed
versionadded; empty case
1 parent 17209f9 commit 568784f

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/categorical.rst

+2
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ The same applies to ``df.append(df_different)``.
653653
Unioning
654654
~~~~~~~~
655655

656+
.. versionadded:: 0.18.2
657+
656658
If you want to combine categoricals that do not necessarily have
657659
the same categories, the `union_categorical` function will
658660
combine a list-like of categoricals. The new categories

pandas/tools/tests/test_concat.py

+3
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,9 @@ def test_union_categorical(self):
965965
with tm.assertRaises(TypeError):
966966
union_categoricals([s, s2])
967967

968+
with tm.assertRaises(ValueError):
969+
union_categoricals([])
970+
968971
def test_concat_bug_1719(self):
969972
ts1 = tm.makeTimeSeries()
970973
ts2 = tm.makeTimeSeries()[::2]

pandas/types/concat.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,18 @@ def union_categoricals(to_union):
223223
TypeError
224224
If any of the categoricals are ordered or all do not
225225
have the same dtype
226+
ValueError
227+
Emmpty list of categoricals passed
226228
"""
227229
from pandas import Index, Categorical
228230

231+
if len(to_union) == 0:
232+
raise ValueError('No Categoricals to union')
233+
234+
first = to_union[0]
229235
if any(c.ordered for c in to_union):
230236
raise TypeError("Can only combine unordered Categoricals")
231237

232-
first = to_union[0]
233238
if not all(com.is_dtype_equal(c.categories.dtype, first.categories.dtype)
234239
for c in to_union):
235240
raise TypeError("dtype of categories must be the same")

0 commit comments

Comments
 (0)