(data, xp=np, dtype=None)
| 270 | |
| 271 | |
| 272 | def asarray(data, xp=np, dtype=None): |
| 273 | if is_duck_array(data): |
| 274 | converted = data |
| 275 | elif is_allowed_extension_array_dtype(dtype): |
| 276 | # data may or may not be an ExtensionArray, so we can't rely on |
| 277 | # np.asarray to call our NEP-18 handler; gotta hook it ourselves |
| 278 | converted = PandasExtensionArray(as_extension_array(data, dtype)) |
| 279 | else: |
| 280 | converted = xp.asarray(data) |
| 281 | |
| 282 | if dtype is None or converted.dtype == dtype: |
| 283 | return converted |
| 284 | |
| 285 | if xp is np or not hasattr(xp, "astype"): |
| 286 | return converted.astype(dtype) |
| 287 | else: |
| 288 | return xp.astype(converted, dtype) |
| 289 | |
| 290 | |
| 291 | def as_shared_dtype(scalars_or_arrays, xp=None): |
no test coverage detected
searching dependent graphs…