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

Method test_diff_array_repr

xarray/tests/test_formatting.py:278–404  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

276 assert len(names) == 2 or hint_chars[1:-1] == ["│"] * (len(names) - 2)
277
278 def test_diff_array_repr(self) -> None:
279 da_a = xr.DataArray(
280 np.array([[1, 2, 3], [4, 5, 6]], dtype="int64"),
281 dims=("x", "y"),
282 coords={
283 "x": np.array(["a", "b"], dtype="U1"),
284 "y": np.array([1, 2, 3], dtype="int64"),
285 },
286 attrs={"units": "m", "description": "desc"},
287 )
288
289 da_b = xr.DataArray(
290 np.array([1, 2], dtype="int64"),
291 dims="x",
292 coords={
293 "x": np.array(["a", "c"], dtype="U1"),
294 "label": ("x", np.array([1, 2], dtype="int64")),
295 },
296 attrs={"units": "kg"},
297 )
298
299 byteorder = "<" if sys.byteorder == "little" else ">"
300 str_dtype = "str" if has_pandas_3 else "object"
301 expected = dedent(
302 f"""\
303 Left and right DataArray objects are not identical
304 Differing dimensions:
305 (x: 2, y: 3) != (x: 2)
306 Differing values:
307 L
308 array([[1, 2, 3],
309 [4, 5, 6]], dtype=int64)
310 R
311 array([1, 2], dtype=int64)
312 Differing coordinates:
313 L * x (x) {byteorder}U1 8B 'a' 'b'
314 R * x (x) {byteorder}U1 8B 'a' 'c'
315 Coordinates only on the left object:
316 * y (y) int64 24B 1 2 3
317 Coordinates only on the right object:
318 label (x) int64 16B 1 2
319 Indexes only on the left object: ['y']
320 Differing indexes:
321 L x Index(['a', 'b'], dtype='{str_dtype}', name='x')
322 R x Index(['a', 'c'], dtype='{str_dtype}', name='x')
323 Differing attributes:
324 L units: m
325 R units: kg
326 Attributes only on the left object:
327 description: desc"""
328 )
329
330 actual = formatting.diff_array_repr(da_a, da_b, "identical")
331 try:
332 assert actual == expected
333 except AssertionError:
334 # depending on platform, dtype may not be shown in numpy array repr
335 assert actual == expected.replace(", dtype=int64", "")

Callers

nothing calls this directly

Calls 3

replaceMethod · 0.80
rstripMethod · 0.80
CustomIndexClass · 0.70

Tested by

no test coverage detected