From 0a407016e994aa74fc4784888e977a05211102f0 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Fri, 29 Mar 2024 11:36:53 -0600 Subject: [PATCH 1/2] Avoid extra read from disk when creating Pandas Index. --- xarray/core/indexes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/indexes.py b/xarray/core/indexes.py index e71c4a6f073..54304cc497f 100644 --- a/xarray/core/indexes.py +++ b/xarray/core/indexes.py @@ -632,7 +632,7 @@ def from_variables( # the checks below. # preserve wrapped pd.Index (if any) - data = getattr(var._data, "array", var.data) + data = getattr(var._data, "array") if hasattr(var._data, "array") else var.data # multi-index level variable: get level index if isinstance(var._data, PandasMultiIndexingAdapter): level = var._data.level From 80b04fee71055881a86b0cb212ceb7655658af53 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Fri, 5 Apr 2024 09:14:45 -0600 Subject: [PATCH 2/2] Update xarray/core/indexes.py Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> --- xarray/core/indexes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/core/indexes.py b/xarray/core/indexes.py index 54304cc497f..a005e1ebfe2 100644 --- a/xarray/core/indexes.py +++ b/xarray/core/indexes.py @@ -632,6 +632,7 @@ def from_variables( # the checks below. # preserve wrapped pd.Index (if any) + # accessing `.data` can load data from disk, so we only access if needed data = getattr(var._data, "array") if hasattr(var._data, "array") else var.data # multi-index level variable: get level index if isinstance(var._data, PandasMultiIndexingAdapter):