(self)
| 2606 | assert (a + a["x"]).name is None |
| 2607 | |
| 2608 | def test_math_with_coords(self) -> None: |
| 2609 | coords = { |
| 2610 | "x": [-1, -2], |
| 2611 | "y": ["ab", "cd", "ef"], |
| 2612 | "lat": (["x", "y"], [[1, 2, 3], [-1, -2, -3]]), |
| 2613 | "c": -999, |
| 2614 | } |
| 2615 | orig = DataArray(np.random.randn(2, 3), coords, dims=["x", "y"]) |
| 2616 | |
| 2617 | actual = orig + 1 |
| 2618 | expected = DataArray(orig.values + 1, orig.coords) |
| 2619 | assert_identical(expected, actual) |
| 2620 | |
| 2621 | actual = 1 + orig |
| 2622 | assert_identical(expected, actual) |
| 2623 | |
| 2624 | actual = orig + orig[0, 0] |
| 2625 | exp_coords = {k: v for k, v in coords.items() if k != "lat"} |
| 2626 | expected = DataArray( |
| 2627 | orig.values + orig.values[0, 0], exp_coords, dims=["x", "y"] |
| 2628 | ) |
| 2629 | assert_identical(expected, actual) |
| 2630 | |
| 2631 | actual = orig[0, 0] + orig |
| 2632 | assert_identical(expected, actual) |
| 2633 | |
| 2634 | actual = orig[0, 0] + orig[-1, -1] |
| 2635 | expected = DataArray(orig.values[0, 0] + orig.values[-1, -1], {"c": -999}) |
| 2636 | assert_identical(expected, actual) |
| 2637 | |
| 2638 | actual = orig[:, 0] + orig[0, :] |
| 2639 | exp_values = orig[:, 0].values[:, None] + orig[0, :].values[None, :] |
| 2640 | expected = DataArray(exp_values, exp_coords, dims=["x", "y"]) |
| 2641 | assert_identical(expected, actual) |
| 2642 | |
| 2643 | actual = orig[0, :] + orig[:, 0] |
| 2644 | assert_identical(expected.transpose(transpose_coords=True), actual) |
| 2645 | |
| 2646 | actual = orig - orig.transpose(transpose_coords=True) |
| 2647 | expected = DataArray(np.zeros((2, 3)), orig.coords) |
| 2648 | assert_identical(expected, actual) |
| 2649 | |
| 2650 | actual = orig.transpose(transpose_coords=True) - orig |
| 2651 | assert_identical(expected.transpose(transpose_coords=True), actual) |
| 2652 | |
| 2653 | alt = DataArray([1, 1], {"x": [-1, -2], "c": "foo", "d": 555}, "x") |
| 2654 | actual = orig + alt |
| 2655 | expected = orig + 1 |
| 2656 | expected.coords["d"] = 555 |
| 2657 | del expected.coords["c"] |
| 2658 | assert_identical(expected, actual) |
| 2659 | |
| 2660 | actual = alt + orig |
| 2661 | assert_identical(expected, actual) |
| 2662 | |
| 2663 | def test_math_with_arithmetic_compat_options(self) -> None: |
| 2664 | # Setting up a clash of non-index coordinate 'foo': |
nothing calls this directly
no test coverage detected