Skip to content

Commit 4729a35

Browse files
committed
Avoid instantiating entire dataset by getting the nbytes in an array
Using `.data` accidentally tries to load the whole lazy arrays into memory. Sad.
1 parent ed60c6c commit 4729a35

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

xarray/core/variable.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ def nbytes(self) -> int:
403403
If the underlying data array does not include ``nbytes``, estimates
404404
the bytes consumed based on the ``size`` and ``dtype``.
405405
"""
406-
if hasattr(self.data, "nbytes"):
407-
return self.data.nbytes
406+
if hasattr(self._data, "nbytes"):
407+
print("can do")
408+
return self._data.nbytes
408409
else:
409410
return self.size * self.dtype.itemsize
410411

0 commit comments

Comments
 (0)