Skip to content

Commit 219d5c1

Browse files
max-sixtyclaude
andcommitted
Simplify DataTree handling in maybe_transpose_dims
Use single map_over_datasets call instead of two separate calls. map_over_datasets supports tuple returns and unpacks them automatically, making the explicit lambda extraction unnecessary. Co-authored-by: Claude <[email protected]>
1 parent 51084f3 commit 219d5c1

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

xarray/testing/assertions.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,8 @@ def _maybe_transpose_dims(a, b):
112112
return a, b
113113

114114
if isinstance(a, DataTree):
115-
# DataTree needs special handling - transpose both trees
116-
# map_over_datasets applies a function over corresponding datasets
117-
transposed_a = map_over_datasets(
118-
lambda a_ds, b_ds: _maybe_transpose_dims(a_ds, b_ds)[0], a, b
119-
)
120-
transposed_b = map_over_datasets(
121-
lambda a_ds, b_ds: _maybe_transpose_dims(a_ds, b_ds)[1], a, b
122-
)
123-
return transposed_a, transposed_b
115+
# map_over_datasets supports tuple returns and unpacks them automatically
116+
return map_over_datasets(_maybe_transpose_dims, a, b)
124117

125118
return _maybe_transpose_dims(a, b)
126119

0 commit comments

Comments
 (0)