(self)
| 1613 | assert_identical(expected, actual) |
| 1614 | |
| 1615 | def test_reset_coords(self) -> None: |
| 1616 | data = DataArray( |
| 1617 | np.zeros((3, 4)), |
| 1618 | {"bar": ("x", ["a", "b", "c"]), "baz": ("y", range(4)), "y": range(4)}, |
| 1619 | dims=["x", "y"], |
| 1620 | name="foo", |
| 1621 | ) |
| 1622 | |
| 1623 | actual1 = data.reset_coords() |
| 1624 | expected1 = Dataset( |
| 1625 | { |
| 1626 | "foo": (["x", "y"], np.zeros((3, 4))), |
| 1627 | "bar": ("x", ["a", "b", "c"]), |
| 1628 | "baz": ("y", range(4)), |
| 1629 | "y": range(4), |
| 1630 | } |
| 1631 | ) |
| 1632 | assert_identical(actual1, expected1) |
| 1633 | |
| 1634 | actual2 = data.reset_coords(["bar", "baz"]) |
| 1635 | assert_identical(actual2, expected1) |
| 1636 | |
| 1637 | actual3 = data.reset_coords("bar") |
| 1638 | expected3 = Dataset( |
| 1639 | {"foo": (["x", "y"], np.zeros((3, 4))), "bar": ("x", ["a", "b", "c"])}, |
| 1640 | {"baz": ("y", range(4)), "y": range(4)}, |
| 1641 | ) |
| 1642 | assert_identical(actual3, expected3) |
| 1643 | |
| 1644 | actual4 = data.reset_coords(["bar"]) |
| 1645 | assert_identical(actual4, expected3) |
| 1646 | |
| 1647 | actual5 = data.reset_coords(drop=True) |
| 1648 | expected5 = DataArray( |
| 1649 | np.zeros((3, 4)), coords={"y": range(4)}, dims=["x", "y"], name="foo" |
| 1650 | ) |
| 1651 | assert_identical(actual5, expected5) |
| 1652 | |
| 1653 | actual6 = data.copy().reset_coords(drop=True) |
| 1654 | assert_identical(actual6, expected5) |
| 1655 | |
| 1656 | actual7 = data.reset_coords("bar", drop=True) |
| 1657 | expected7 = DataArray( |
| 1658 | np.zeros((3, 4)), |
| 1659 | {"baz": ("y", range(4)), "y": range(4)}, |
| 1660 | dims=["x", "y"], |
| 1661 | name="foo", |
| 1662 | ) |
| 1663 | assert_identical(actual7, expected7) |
| 1664 | |
| 1665 | with pytest.raises(ValueError, match=r"cannot be found"): |
| 1666 | data.reset_coords("foo", drop=True) |
| 1667 | with pytest.raises(ValueError, match=r"cannot be found"): |
| 1668 | data.reset_coords("not_found") |
| 1669 | with pytest.raises(ValueError, match=r"cannot remove index"): |
| 1670 | data.reset_coords("y") |
| 1671 | |
| 1672 | # non-dimension index coordinate |
nothing calls this directly
no test coverage detected