Total bytes consumed by the elements of the data array. If the underlying data array does not include ``nbytes``, estimates the bytes consumed based on the ``size`` and ``dtype``.
(self)
| 461 | |
| 462 | @property |
| 463 | def nbytes(self) -> _IntOrUnknown: |
| 464 | """ |
| 465 | Total bytes consumed by the elements of the data array. |
| 466 | |
| 467 | If the underlying data array does not include ``nbytes``, estimates |
| 468 | the bytes consumed based on the ``size`` and ``dtype``. |
| 469 | """ |
| 470 | from xarray.namedarray._array_api import _get_data_namespace |
| 471 | |
| 472 | if hasattr(self._data, "nbytes"): |
| 473 | return self._data.nbytes # type: ignore[no-any-return] |
| 474 | |
| 475 | if hasattr(self.dtype, "itemsize"): |
| 476 | itemsize = self.dtype.itemsize |
| 477 | elif isinstance(self._data, _arrayapi): |
| 478 | xp = _get_data_namespace(self) |
| 479 | |
| 480 | if xp.isdtype(self.dtype, "bool"): |
| 481 | itemsize = 1 |
| 482 | elif xp.isdtype(self.dtype, "integral"): |
| 483 | itemsize = xp.iinfo(self.dtype).bits // 8 |
| 484 | else: |
| 485 | itemsize = xp.finfo(self.dtype).bits // 8 |
| 486 | else: |
| 487 | raise TypeError( |
| 488 | "cannot compute the number of bytes (no array API nor nbytes / itemsize)" |
| 489 | ) |
| 490 | |
| 491 | return self.size * itemsize |
| 492 | |
| 493 | @property |
| 494 | def dims(self) -> _Dims: |
nothing calls this directly
no test coverage detected