MCPcopy
hub / github.com/pydata/xarray / assert_identical

Function assert_identical

xarray/testing/assertions.py:157–196  ·  view source on GitHub ↗

Like :py:func:`xarray.testing.assert_equal`, but also matches the objects' names and attributes. Raises an AssertionError if two objects are not identical. For DataTree objects, assert_identical is mapped over all Datasets on each node, with the DataTrees being identical if both ar

(a, b)

Source from the content-addressed store, hash-verified

155
156@ensure_warnings
157def assert_identical(a, b):
158 """Like :py:func:`xarray.testing.assert_equal`, but also matches the
159 objects' names and attributes.
160
161 Raises an AssertionError if two objects are not identical.
162
163 For DataTree objects, assert_identical is mapped over all Datasets on each
164 node, with the DataTrees being identical if both are isomorphic and the
165 corresponding Datasets at each node are themselves identical.
166
167 Parameters
168 ----------
169 a : xarray.Dataset, xarray.DataArray, xarray.Variable or xarray.Coordinates
170 The first object to compare.
171 b : xarray.Dataset, xarray.DataArray, xarray.Variable or xarray.Coordinates
172 The second object to compare.
173
174 See Also
175 --------
176 assert_equal, assert_allclose, Dataset.equals, DataArray.equals
177 """
178 __tracebackhide__ = True
179 assert type(a) is type(b) or (
180 isinstance(a, Coordinates) and isinstance(b, Coordinates)
181 )
182 if isinstance(a, Variable):
183 assert a.identical(b), formatting.diff_array_repr(a, b, "identical")
184 elif isinstance(a, DataArray):
185 assert a.name == b.name, (
186 f"DataArray names are different. L: {a.name}, R: {b.name}"
187 )
188 assert a.identical(b), formatting.diff_array_repr(a, b, "identical")
189 elif isinstance(a, Dataset | Variable):
190 assert a.identical(b), formatting.diff_dataset_repr(a, b, "identical")
191 elif isinstance(a, Coordinates):
192 assert a.identical(b), formatting.diff_coords_repr(a, b, "identical")
193 elif isinstance(a, DataTree):
194 assert a.identical(b), diff_datatree_repr(a, b, "identical")
195 else:
196 raise TypeError(f"{type(a)} not supported by assertion comparison")
197
198
199@ensure_warnings

Calls 3

diff_datatree_reprFunction · 0.90
typeFunction · 0.85
identicalMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…