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

Method test_align

xarray/tests/test_dataset.py:2560–2603  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2558 assert_identical(expected_y2, y2)
2559
2560 def test_align(self) -> None:
2561 left = create_test_data()
2562 right = left.copy(deep=True)
2563 right["dim3"] = ("dim3", list("cdefghijkl"))
2564 right["var3"][:-2] = right["var3"][2:].values
2565 right["var3"][-2:] = np.random.randn(*right["var3"][-2:].shape)
2566 right["numbers"][:-2] = right["numbers"][2:].values
2567 right["numbers"][-2:] = -10
2568
2569 intersection = list("cdefghij")
2570 union = list("abcdefghijkl")
2571
2572 left2, right2 = align(left, right, join="inner")
2573 assert_array_equal(left2["dim3"], intersection)
2574 assert_identical(left2, right2)
2575
2576 left2, right2 = align(left, right, join="outer")
2577
2578 assert_array_equal(left2["dim3"], union)
2579 assert_equal(left2["dim3"].variable, right2["dim3"].variable)
2580
2581 assert_identical(left2.sel(dim3=intersection), right2.sel(dim3=intersection))
2582 assert np.isnan(left2["var3"][-2:]).all()
2583 assert np.isnan(right2["var3"][:2]).all()
2584
2585 left2, right2 = align(left, right, join="left")
2586 assert_equal(left2["dim3"].variable, right2["dim3"].variable)
2587 assert_equal(left2["dim3"].variable, left["dim3"].variable)
2588
2589 assert_identical(left2.sel(dim3=intersection), right2.sel(dim3=intersection))
2590 assert np.isnan(right2["var3"][:2]).all()
2591
2592 left2, right2 = align(left, right, join="right")
2593 assert_equal(left2["dim3"].variable, right2["dim3"].variable)
2594 assert_equal(left2["dim3"].variable, right["dim3"].variable)
2595
2596 assert_identical(left2.sel(dim3=intersection), right2.sel(dim3=intersection))
2597
2598 assert np.isnan(left2["var3"][-2:]).all()
2599
2600 with pytest.raises(ValueError, match=r"invalid value for join"):
2601 align(left, right, join="foobar") # type: ignore[call-overload]
2602 with pytest.raises(TypeError):
2603 align(left, right, foo="bar") # type: ignore[call-overload]
2604
2605 def test_align_exact(self) -> None:
2606 left = xr.Dataset(coords={"x": [0, 1]})

Callers

nothing calls this directly

Calls 7

create_test_dataFunction · 0.90
alignFunction · 0.90
assert_identicalFunction · 0.90
assert_equalFunction · 0.90
copyMethod · 0.45
selMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected