Skip to content

Commit 0ecc82d

Browse files
committed
add a static method to compare indexing overators
1 parent f3a4d98 commit 0ecc82d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

xarray_array_testing/base.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from abc import ABC
33
from types import ModuleType
44

5+
import numpy as np
56
import numpy.testing as npt
7+
import xarray as xr
68
from xarray.namedarray._typing import duckarray
79

810

@@ -24,3 +26,23 @@ def array_strategy_fn(*, shape, dtype):
2426
@staticmethod
2527
def assert_equal(a, b):
2628
npt.assert_equal(a, b)
29+
30+
@staticmethod
31+
def assert_dimension_indexers_equal(a, b):
32+
assert type(a) is type(b), f"types don't match: {type(a)} vs {type(b)}"
33+
34+
if isinstance(a, dict):
35+
assert a.keys() == b.keys(), f"Different dimensions: {list(a)} vs {list(b)}"
36+
37+
values = ((a[k], b[k]) for k in a)
38+
assert all(
39+
(
40+
isinstance(v1, xr.Variable)
41+
and isinstance(v2, xr.Variable)
42+
and v1.dims == v2.dims
43+
and np.equal(v1.data, v2.data)
44+
)
45+
for v1, v2 in values
46+
), "Differing indexers"
47+
else:
48+
npt.assert_equal(a, b)

0 commit comments

Comments
 (0)