The Variable's data as an array. The underlying array type (e.g. dask, sparse, pint) is preserved. See Also -------- Variable.to_numpy Variable.as_numpy Variable.values
(self)
| 439 | |
| 440 | @property |
| 441 | def data(self): |
| 442 | """ |
| 443 | The Variable's data as an array. The underlying array type |
| 444 | (e.g. dask, sparse, pint) is preserved. |
| 445 | |
| 446 | See Also |
| 447 | -------- |
| 448 | Variable.to_numpy |
| 449 | Variable.as_numpy |
| 450 | Variable.values |
| 451 | """ |
| 452 | if isinstance(self._data, PandasExtensionArray): |
| 453 | duck_array = self._data.array |
| 454 | elif isinstance(self._data, indexing.ExplicitlyIndexed): |
| 455 | duck_array = self._data.get_duck_array() |
| 456 | elif is_duck_array(self._data): |
| 457 | duck_array = self._data |
| 458 | else: |
| 459 | duck_array = self.values |
| 460 | if isinstance(duck_array, PandasExtensionArray): |
| 461 | # even though PandasExtensionArray is a duck array, |
| 462 | # we should not return the PandasExtensionArray wrapper, |
| 463 | # and instead return the underlying data. |
| 464 | return duck_array.array |
| 465 | return duck_array |
| 466 | |
| 467 | @data.setter # type: ignore[override,unused-ignore] |
| 468 | def data(self, data: T_DuckArray | np.typing.ArrayLike) -> None: |
nothing calls this directly
no test coverage detected