From 254e2764c1b9d64cc906e1cd9cb1dd62762a4a33 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Thu, 19 Dec 2024 17:16:52 +0100 Subject: [PATCH] stronger docstrings --- src/zarr/core/array.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 452f6e855..2849907f9 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -977,9 +977,16 @@ def _iter_chunk_regions( @property def nbytes(self) -> int: """ - The number of bytes that can be stored in the chunks of this array. + The total number of bytes that can be stored in the chunks of this array. + + Notes + ----- + This value is calculated by multiplying the number of elements in the array and the size + of each element, the latter of which is determined by the dtype of the array. + For this reason, ``nbytes`` will likely be inaccurate for arrays with variable-length + dtypes. It is not possible to determine the size of an array with variable-length elements + from the shape and dtype alone. """ - # TODO: how can this be meaningful for variable-length types? return self.size * self.dtype.itemsize async def _get_selection( @@ -1741,7 +1748,15 @@ def _iter_chunk_coords( @property def nbytes(self) -> int: """ - The number of bytes that can be stored in this array. + The total number of bytes that can be stored in the chunks of this array. + + Notes + ----- + This value is calculated by multiplying the number of elements in the array and the size + of each element, the latter of which is determined by the dtype of the array. + For this reason, ``nbytes`` will likely be inaccurate for arrays with variable-length + dtypes. It is not possible to determine the size of an array with variable-length elements + from the shape and dtype alone. """ return self._async_array.nbytes