Skip to content

Commit

Permalink
Avoid extra read from disk when creating Pandas Index. (#8893)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
dcherian and max-sixty committed May 7, 2024
1 parent 4e9d557 commit 322e670
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion xarray/core/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,8 @@ def from_variables(
# the checks below.

# preserve wrapped pd.Index (if any)
data = getattr(var._data, "array", var.data)
# 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):
level = var._data.level
Expand Down

0 comments on commit 322e670

Please sign in to comment.