(
array_or_scalar: np.typing.ArrayLike | T_ExtensionArray,
dtype: ExtensionDtype | DTypeLikeSave | None,
copy: bool = False,
)
| 95 | |
| 96 | |
| 97 | def as_extension_array( |
| 98 | array_or_scalar: np.typing.ArrayLike | T_ExtensionArray, |
| 99 | dtype: ExtensionDtype | DTypeLikeSave | None, |
| 100 | copy: bool = False, |
| 101 | ) -> ExtensionArray: |
| 102 | if is_scalar(array_or_scalar): |
| 103 | return dtype.construct_array_type()._from_sequence( # type: ignore[union-attr] |
| 104 | [array_or_scalar], dtype=dtype |
| 105 | ) |
| 106 | else: |
| 107 | # pandas-stubs is overly strict about astype's dtype parameter and return type; |
| 108 | # ExtensionArray.astype accepts ExtensionDtype and returns ExtensionArray |
| 109 | return array_or_scalar.astype(dtype, copy=copy) # type: ignore[union-attr,return-value,arg-type] |
| 110 | |
| 111 | |
| 112 | @implements(np.result_type) |
no test coverage detected
searching dependent graphs…