From 8826c144ab4735d9dc8f6df02e016fa06d38a922 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index bb988392f50..8cf46c4b88a 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -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