Skip to content

Commit 2046049

Browse files
dcherianmax-sixty
authored andcommitted
Avoid extra read from disk when creating Pandas Index. (#8893)
* Avoid extra read from disk when creating Pandas Index. * Update xarray/core/indexes.py Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> --------- Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
1 parent 2c5216f commit 2046049

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

xarray/core/indexes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,8 @@ def from_variables(
632632
# the checks below.
633633

634634
# preserve wrapped pd.Index (if any)
635-
data = getattr(var._data, "array", var.data)
635+
# accessing `.data` can load data from disk, so we only access if needed
636+
data = getattr(var._data, "array") if hasattr(var._data, "array") else var.data
636637
# multi-index level variable: get level index
637638
if isinstance(var._data, PandasMultiIndexingAdapter):
638639
level = var._data.level

0 commit comments

Comments
 (0)