@@ -194,24 +194,22 @@ def union_categoricals(
194
194
195
195
Examples
196
196
--------
197
- >>> from pandas.api.types import union_categoricals
198
-
199
197
If you want to combine categoricals that do not necessarily have
200
198
the same categories, `union_categoricals` will combine a list-like
201
199
of categoricals. The new categories will be the union of the
202
200
categories being combined.
203
201
204
202
>>> a = pd.Categorical(["b", "c"])
205
203
>>> b = pd.Categorical(["a", "b"])
206
- >>> union_categoricals([a, b])
204
+ >>> pd.api.types. union_categoricals([a, b])
207
205
['b', 'c', 'a', 'b']
208
206
Categories (3, object): ['b', 'c', 'a']
209
207
210
208
By default, the resulting categories will be ordered as they appear
211
209
in the `categories` of the data. If you want the categories to be
212
210
lexsorted, use `sort_categories=True` argument.
213
211
214
- >>> union_categoricals([a, b], sort_categories=True)
212
+ >>> pd.api.types. union_categoricals([a, b], sort_categories=True)
215
213
['b', 'c', 'a', 'b']
216
214
Categories (3, object): ['a', 'b', 'c']
217
215
@@ -221,15 +219,15 @@ def union_categoricals(
221
219
222
220
>>> a = pd.Categorical(["a", "b"], ordered=True)
223
221
>>> b = pd.Categorical(["a", "b", "a"], ordered=True)
224
- >>> union_categoricals([a, b])
222
+ >>> pd.api.types. union_categoricals([a, b])
225
223
['a', 'b', 'a', 'b', 'a']
226
224
Categories (2, object): ['a' < 'b']
227
225
228
226
Raises `TypeError` because the categories are ordered and not identical.
229
227
230
228
>>> a = pd.Categorical(["a", "b"], ordered=True)
231
229
>>> b = pd.Categorical(["a", "b", "c"], ordered=True)
232
- >>> union_categoricals([a, b])
230
+ >>> pd.api.types. union_categoricals([a, b])
233
231
Traceback (most recent call last):
234
232
...
235
233
TypeError: to union ordered Categoricals, all categories must be the same
@@ -241,7 +239,7 @@ def union_categoricals(
241
239
242
240
>>> a = pd.Categorical(["a", "b", "c"], ordered=True)
243
241
>>> b = pd.Categorical(["c", "b", "a"], ordered=True)
244
- >>> union_categoricals([a, b], ignore_order=True)
242
+ >>> pd.api.types. union_categoricals([a, b], ignore_order=True)
245
243
['a', 'b', 'c', 'c', 'b', 'a']
246
244
Categories (3, object): ['a', 'b', 'c']
247
245
@@ -251,7 +249,7 @@ def union_categoricals(
251
249
252
250
>>> a = pd.Series(["b", "c"], dtype='category')
253
251
>>> b = pd.Series(["a", "b"], dtype='category')
254
- >>> union_categoricals([a, b])
252
+ >>> pd.api.types. union_categoricals([a, b])
255
253
['b', 'c', 'a', 'b']
256
254
Categories (3, object): ['b', 'c', 'a']
257
255
"""
0 commit comments