Skip to content

Commit

Permalink
Handle support for older xarray
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed Sep 29, 2023
1 parent 6d22e34 commit 50470b3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions qcodes/dataset/exporters/export_to_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@ def _load_to_xarray_dataarray_dict_no_metadata(
on_grid = index_prod == len(index)
if not on_grid:
assert isinstance(df.index, pd.MultiIndex)
coords = xr.Coordinates.from_pandas_multiindex(
df.index, "multi_index"
)
xrdarray = xr.DataArray(df[name], coords=coords)

if hasattr(xr, "Coordinates"):
coords = xr.Coordinates.from_pandas_multiindex(
df.index, "multi_index"
)
xrdarray = xr.DataArray(df[name], coords=coords)
else:
# support xarray < 2023.8.0, can be removed when we drop support for that

Check notice on line 103 in qcodes/dataset/exporters/export_to_xarray.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

qcodes/dataset/exporters/export_to_xarray.py#L103

Line too long (97/88)
xrdarray = xr.DataArray(df[name], [("multi_index", df.index)])

Check warning on line 104 in qcodes/dataset/exporters/export_to_xarray.py

View check run for this annotation

Codecov / codecov/patch

qcodes/dataset/exporters/export_to_xarray.py#L104

Added line #L104 was not covered by tests
else:
xrdarray = df.to_xarray().get(name, xr.DataArray())

Expand Down

0 comments on commit 50470b3

Please sign in to comment.