MCPcopy
hub / github.com/dask/dask / clear_known_categories

Function clear_known_categories

dask/dataframe/utils.py:220–258  ·  view source on GitHub ↗

Set categories to be unknown. Parameters ---------- x : DataFrame, Series, Index cols : iterable, optional If x is a DataFrame, set only categoricals in these columns to unknown. By default, all categorical columns are set to unknown categoricals index : bool, op

(x, cols=None, index=True, dtype_backend=None)

Source from the content-addressed store, hash-verified

218
219
220def clear_known_categories(x, cols=None, index=True, dtype_backend=None):
221 """Set categories to be unknown.
222
223 Parameters
224 ----------
225 x : DataFrame, Series, Index
226 cols : iterable, optional
227 If x is a DataFrame, set only categoricals in these columns to unknown.
228 By default, all categorical columns are set to unknown categoricals
229 index : bool, optional
230 If True and x is a Series or DataFrame, set the clear known categories
231 in the index as well.
232 dtype_backend : string, optional
233 If set to PyArrow, the categorical dtype is implemented as a PyArrow
234 dictionary
235 """
236 if dtype_backend == "pyarrow":
237 # Right now Categorical with PyArrow is implemented as dictionary and
238 # categorical accessor is not yet available
239 return x
240
241 if not is_index_like(x):
242 x = x.copy()
243 if is_dataframe_like(x):
244 mask = x.dtypes == "category"
245 if cols is None:
246 cols = mask[mask].index
247 elif not mask.loc[cols].all():
248 raise ValueError("Not all columns are categoricals")
249 for c in cols:
250 x[c] = x[c].cat.set_categories([UNKNOWN_CATEGORIES])
251 elif is_series_like(x):
252 if is_categorical_dtype_dispatch(x.dtype):
253 x = x.cat.set_categories([UNKNOWN_CATEGORIES])
254 if index and is_categorical_dtype_dispatch(x.index.dtype):
255 x.index = x.index.set_categories([UNKNOWN_CATEGORIES])
256 elif is_categorical_dtype_dispatch(x.dtype):
257 x = x.set_categories([UNKNOWN_CATEGORIES])
258 return x
259
260
261def _empty_series(name, dtype, index=None):

Callers 4

_metaMethod · 0.90
_metaMethod · 0.90
text_blocks_to_pandasFunction · 0.90
_create_dd_metaMethod · 0.90

Calls 5

is_index_likeFunction · 0.90
is_dataframe_likeFunction · 0.90
is_series_likeFunction · 0.90
copyMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…