(dtype)
| 687 | |
| 688 | |
| 689 | def 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( |
nothing calls this directly
no test coverage detected
searching dependent graphs…