MCPcopy
hub / github.com/pandas-dev/pandas / _ensure_arraylike

Function _ensure_arraylike

pandas/core/algorithms.py:228–253  ·  view source on GitHub ↗

ensure that we are arraylike if not already

(values, func_name: str)

Source from the content-addressed store, hash-verified

226
227
228def _ensure_arraylike(values, func_name: str) -> ArrayLike:
229 """
230 ensure that we are arraylike if not already
231 """
232 if not isinstance(
233 values,
234 (ABCIndex, ABCSeries, ABCExtensionArray, np.ndarray, ABCNumpyExtensionArray),
235 ):
236 # GH#52986
237 if func_name != "isin-targets":
238 # Make an exception for the comps argument in isin.
239 raise TypeError(
240 f"{func_name} requires a Series, Index, "
241 f"ExtensionArray, np.ndarray or NumpyExtensionArray "
242 f"got {type(values).__name__}."
243 )
244
245 inferred = lib.infer_dtype(values, skipna=False)
246 if inferred in ["mixed", "string", "mixed-integer"]:
247 # "mixed-integer" to ensure we do not cast ["ss", 42] to str GH#22160
248 if isinstance(values, tuple):
249 values = list(values)
250 values = construct_1d_object_array_from_listlike(values)
251 else:
252 values = np.asarray(values)
253 return values
254
255
256_hashtables = {

Callers 5

unique_with_maskFunction · 0.85
isinFunction · 0.85
factorizeFunction · 0.85
value_counts_internalFunction · 0.85
modeFunction · 0.85

Tested by

no test coverage detected