@@ -191,42 +191,42 @@ def union_categoricals(
191
191
192
192
Examples
193
193
--------
194
- >>> from pandas.api.types import union_categoricals
194
+ >>> import pandas as pd
195
195
196
196
If you want to combine categoricals that do not necessarily have
197
- the same categories, `union_categoricals` will combine a list-like
197
+ the same categories, `pd.api.types. union_categoricals` will combine a list-like
198
198
of categoricals. The new categories will be the union of the
199
199
categories being combined.
200
200
201
201
>>> a = pd.Categorical(["b", "c"])
202
202
>>> b = pd.Categorical(["a", "b"])
203
- >>> union_categoricals([a, b])
203
+ >>> pd.api.types. union_categoricals([a, b])
204
204
['b', 'c', 'a', 'b']
205
205
Categories (3, object): ['b', 'c', 'a']
206
206
207
207
By default, the resulting categories will be ordered as they appear
208
208
in the `categories` of the data. If you want the categories to be
209
209
lexsorted, use `sort_categories=True` argument.
210
210
211
- >>> union_categoricals([a, b], sort_categories=True)
211
+ >>> pd.api.types. union_categoricals([a, b], sort_categories=True)
212
212
['b', 'c', 'a', 'b']
213
213
Categories (3, object): ['a', 'b', 'c']
214
214
215
- `union_categoricals` also works with the case of combining two
215
+ `pd.api.types. union_categoricals` also works with the case of combining two
216
216
categoricals of the same categories and order information (e.g. what
217
217
you could also `append` for).
218
218
219
219
>>> a = pd.Categorical(["a", "b"], ordered=True)
220
220
>>> b = pd.Categorical(["a", "b", "a"], ordered=True)
221
- >>> union_categoricals([a, b])
221
+ >>> pd.api.types. union_categoricals([a, b])
222
222
['a', 'b', 'a', 'b', 'a']
223
223
Categories (2, object): ['a' < 'b']
224
224
225
225
Raises `TypeError` because the categories are ordered and not identical.
226
226
227
227
>>> a = pd.Categorical(["a", "b"], ordered=True)
228
228
>>> b = pd.Categorical(["a", "b", "c"], ordered=True)
229
- >>> union_categoricals([a, b])
229
+ >>> pd.api.types. union_categoricals([a, b])
230
230
Traceback (most recent call last):
231
231
...
232
232
TypeError: to union ordered Categoricals, all categories must be the same
@@ -238,17 +238,17 @@ def union_categoricals(
238
238
239
239
>>> a = pd.Categorical(["a", "b", "c"], ordered=True)
240
240
>>> b = pd.Categorical(["c", "b", "a"], ordered=True)
241
- >>> union_categoricals([a, b], ignore_order=True)
241
+ >>> pd.api.types. union_categoricals([a, b], ignore_order=True)
242
242
['a', 'b', 'c', 'c', 'b', 'a']
243
243
Categories (3, object): ['a', 'b', 'c']
244
244
245
- `union_categoricals` also works with a `CategoricalIndex`, or `Series`
245
+ `pd.api.types. union_categoricals` also works with a `CategoricalIndex`, or `Series`
246
246
containing categorical data, but note that the resulting array will
247
247
always be a plain `Categorical`
248
248
249
249
>>> a = pd.Series(["b", "c"], dtype='category')
250
250
>>> b = pd.Series(["a", "b"], dtype='category')
251
- >>> union_categoricals([a, b])
251
+ >>> pd.api.types. union_categoricals([a, b])
252
252
['b', 'c', 'a', 'b']
253
253
Categories (3, object): ['b', 'c', 'a']
254
254
"""
0 commit comments