MCPcopy Index your code
hub / github.com/pydata/xarray / test_broadcast_dataset

Function test_broadcast_dataset

xarray/tests/test_units.py:689–722  ·  view source on GitHub ↗
(dtype)

Source from the content-addressed store, hash-verified

687
688
689def test_broadcast_dataset(dtype):
690 # uses align internally so more thorough tests are not needed
691 array1 = np.linspace(0, 10, 2) * unit_registry.Pa
692 array2 = np.linspace(0, 10, 3) * unit_registry.Pa
693
694 x1 = np.arange(2)
695 y1 = np.arange(3)
696
697 x2 = np.arange(2, 4)
698 y2 = np.arange(3, 6)
699
700 ds = xr.Dataset(
701 data_vars={"a": ("x", array1), "b": ("y", array2)}, coords={"x": x1, "y": y1}
702 )
703 other = xr.Dataset(
704 data_vars={
705 "a": ("x", array1.to(unit_registry.hPa)),
706 "b": ("y", array2.to(unit_registry.hPa)),
707 },
708 coords={"x": x2, "y": y2},
709 )
710
711 units_a = extract_units(ds)
712 units_b = extract_units(other)
713 expected_a, expected_b = xr.broadcast(strip_units(ds), strip_units(other))
714 expected_a = attach_units(expected_a, units_a)
715 expected_b = attach_units(expected_b, units_b)
716
717 actual_a, actual_b = xr.broadcast(ds, other)
718
719 assert_units_equal(expected_a, actual_a)
720 assert_identical(expected_a, actual_a)
721 assert_units_equal(expected_b, actual_b)
722 assert_identical(expected_b, actual_b)
723
724
725@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 7

assert_identicalFunction · 0.90
extract_unitsFunction · 0.85
strip_unitsFunction · 0.85
attach_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
arangeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…