ensure that we are arraylike if not already
(values, func_name: str)
| 226 | |
| 227 | |
| 228 | def _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 = { |
no test coverage detected