Two Datasets are equal if they have matching variables and coordinates, all of which are equal. Datasets can still be equal (like pandas objects) if they have NaN values in the same locations. This method is necessary because `v1 == v2` for ``Dataset`` does
(self, other: Self)
| 1615 | return False |
| 1616 | |
| 1617 | def equals(self, other: Self) -> bool: |
| 1618 | """Two Datasets are equal if they have matching variables and |
| 1619 | coordinates, all of which are equal. |
| 1620 | |
| 1621 | Datasets can still be equal (like pandas objects) if they have NaN |
| 1622 | values in the same locations. |
| 1623 | |
| 1624 | This method is necessary because `v1 == v2` for ``Dataset`` |
| 1625 | does element-wise comparisons (like numpy.ndarrays). |
| 1626 | |
| 1627 | Examples |
| 1628 | -------- |
| 1629 | |
| 1630 | # 2D array with shape (1, 3) |
| 1631 | |
| 1632 | >>> data = np.array([[1, 2, 3]]) |
| 1633 | >>> dataset1 = xr.Dataset( |
| 1634 | ... {"variable_name": (("space", "time"), data)}, |
| 1635 | ... coords={"space": [0], "time": [0, 1, 2]}, |
| 1636 | ... ) |
| 1637 | >>> dataset1 |
| 1638 | <xarray.Dataset> Size: 56B |
| 1639 | Dimensions: (space: 1, time: 3) |
| 1640 | Coordinates: |
| 1641 | * space (space) int64 8B 0 |
| 1642 | * time (time) int64 24B 0 1 2 |
| 1643 | Data variables: |
| 1644 | variable_name (space, time) int64 24B 1 2 3 |
| 1645 | |
| 1646 | # 2D array with shape (3, 1) |
| 1647 | |
| 1648 | >>> data = np.array([[1], [2], [3]]) |
| 1649 | >>> dataset2 = xr.Dataset( |
| 1650 | ... {"variable_name": (("time", "space"), data)}, |
| 1651 | ... coords={"time": [0, 1, 2], "space": [0]}, |
| 1652 | ... ) |
| 1653 | >>> dataset2 |
| 1654 | <xarray.Dataset> Size: 56B |
| 1655 | Dimensions: (time: 3, space: 1) |
| 1656 | Coordinates: |
| 1657 | * time (time) int64 24B 0 1 2 |
| 1658 | * space (space) int64 8B 0 |
| 1659 | Data variables: |
| 1660 | variable_name (time, space) int64 24B 1 2 3 |
| 1661 | >>> dataset1.equals(dataset2) |
| 1662 | False |
| 1663 | |
| 1664 | >>> dataset1.broadcast_equals(dataset2) |
| 1665 | True |
| 1666 | |
| 1667 | .equals returns True if two Datasets have the same values, dimensions, and coordinates. .broadcast_equals returns True if the |
| 1668 | results of broadcasting two Datasets against each other have the same values, dimensions, and coordinates. |
| 1669 | |
| 1670 | Similar for missing values too: |
| 1671 | |
| 1672 | >>> ds1 = xr.Dataset( |
| 1673 | ... { |
| 1674 | ... "temperature": (["x", "y"], [[1, np.nan], [3, 4]]), |