MCPcopy Index your code
hub / github.com/scikit-learn/scikit-learn / _unique_python

Function _unique_python

sklearn/utils/_encode.py:171–194  ·  view source on GitHub ↗
(values, *, return_inverse, return_counts)

Source from the content-addressed store, hash-verified

169
170
171def _unique_python(values, *, return_inverse, return_counts):
172 # Only used in `_uniques`, see docstring there for details
173 try:
174 uniques_set = set(values)
175 uniques_set, missing_values = _extract_missing(uniques_set)
176
177 uniques = sorted(uniques_set)
178 uniques.extend(missing_values.to_list())
179 uniques = np.array(uniques, dtype=values.dtype)
180 except TypeError:
181 types = sorted(t.__qualname__ for t in set(type(v) for v in values))
182 raise TypeError(
183 "Encoders require their input argument must be uniformly "
184 f"strings or numbers. Got {types}"
185 )
186 ret = (uniques,)
187
188 if return_inverse:
189 ret += (_map_to_integer(values, uniques),)
190
191 if return_counts:
192 ret += (_get_counts(values, uniques),)
193
194 return ret[0] if len(ret) == 1 else ret
195
196
197def _encode(values, *, uniques, check_unknown=True):

Callers 1

_uniqueFunction · 0.85

Calls 4

_extract_missingFunction · 0.85
_map_to_integerFunction · 0.85
_get_countsFunction · 0.85
to_listMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…