From 4729a35b3b32eea21017cec540ce465f86523d58 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 4 Dec 2022 22:29:02 -0500 Subject: [PATCH] Avoid instantiating entire dataset by getting the nbytes in an array Using `.data` accidentally tries to load the whole lazy arrays into memory. Sad. --- xarray/core/variable.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index bb988392f50..5b11509cd38 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -403,8 +403,9 @@ 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"): + print("can do") + return self._data.nbytes else: return self.size * self.dtype.itemsize