Skip to content

Commit e7b87d6

Browse files
authored
Merge pull request #101 from mikapfl/new-xarray-compat
Replace hacks that worked on old versions of xarray with proper xarray calls
2 parents 14ea9e2 + 7f06ffc commit e7b87d6

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* The latest (not-yet-released) version of xarray contains a rework of indexing
2+
and some small changes to our I/O functions are necessary to support both old
3+
and new xarray.

primap2/_setters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def set(
276276
# to broadcast value only to sel, but would need more careful handling
277277
# later.
278278
if new == "extend":
279-
value, expanded = xr.broadcast(value, self._da)
279+
expanded, value = xr.broadcast(self._da, value)
280280
else:
281281
expanded = self._da
282282
value = value.broadcast_like(expanded)

primap2/pm2io/_interchange_format.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,12 @@ def from_interchange_format(
340340
for entity, dims in dimensions.items():
341341
da_entity = da.loc[{entity_col: entity}]
342342
# we still have a full MultiIndex, so trim it to the relevant dimensions
343-
da_entity["index"] = da_entity.indexes["index"].droplevel(
344-
list(index_cols - set(dims))
345-
)
343+
da_entity = da_entity.reset_index(list(index_cols - set(dims)), drop=True)
344+
# depending on the version of xarray, an atomic, 0-dimensional coord
345+
# for the entity remains. we have to remove it to be able to combine the
346+
# dataset afterwards.
347+
if entity_col in da_entity.coords:
348+
da_entity = da_entity.drop(entity_col)
346349
# now we can safely unstack the index
347350
data_vars[entity] = da_entity.unstack("index").astype(dtypes[entity])
348351

0 commit comments

Comments
 (0)