Skip to content

Commit

Permalink
Avoid instantiating entire dataset by getting the nbytes in an array
Browse files Browse the repository at this point in the history
Using `.data` accidentally tries to load the whole lazy arrays into
memory.

Sad.
  • Loading branch information
hmaarrfk committed Dec 5, 2022
1 parent ed60c6c commit 8826c14
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ def nbytes(self) -> int:
If the underlying data array does not include ``nbytes``, estimates
the bytes consumed based on the ``size`` and ``dtype``.
"""
if hasattr(self.data, "nbytes"):
return self.data.nbytes
if hasattr(self._data, "nbytes"):
return self._data.nbytes
else:
return self.size * self.dtype.itemsize

Expand Down

0 comments on commit 8826c14

Please sign in to comment.