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

Method broadcast_equals

xarray/core/dataset.py:1550–1615  ·  view source on GitHub ↗

Two Datasets are broadcast equal if they are equal after broadcasting all variables against each other. For example, variables that are scalar in one dataset but non-scalar in the other dataset can still be broadcast equal if the the non-scalar variable is a constant

(self, other: Self)

Source from the content-addressed store, hash-verified

1548 )
1549
1550 def broadcast_equals(self, other: Self) -> bool:
1551 """Two Datasets are broadcast equal if they are equal after
1552 broadcasting all variables against each other.
1553
1554 For example, variables that are scalar in one dataset but non-scalar in
1555 the other dataset can still be broadcast equal if the the non-scalar
1556 variable is a constant.
1557
1558 Examples
1559 --------
1560
1561 # 2D array with shape (1, 3)
1562
1563 >>> data = np.array([[1, 2, 3]])
1564 >>> a = xr.Dataset(
1565 ... {"variable_name": (("space", "time"), data)},
1566 ... coords={"space": [0], "time": [0, 1, 2]},
1567 ... )
1568 >>> a
1569 <xarray.Dataset> Size: 56B
1570 Dimensions: (space: 1, time: 3)
1571 Coordinates:
1572 * space (space) int64 8B 0
1573 * time (time) int64 24B 0 1 2
1574 Data variables:
1575 variable_name (space, time) int64 24B 1 2 3
1576
1577 # 2D array with shape (3, 1)
1578
1579 >>> data = np.array([[1], [2], [3]])
1580 >>> b = xr.Dataset(
1581 ... {"variable_name": (("time", "space"), data)},
1582 ... coords={"time": [0, 1, 2], "space": [0]},
1583 ... )
1584 >>> b
1585 <xarray.Dataset> Size: 56B
1586 Dimensions: (time: 3, space: 1)
1587 Coordinates:
1588 * time (time) int64 24B 0 1 2
1589 * space (space) int64 8B 0
1590 Data variables:
1591 variable_name (time, space) int64 24B 1 2 3
1592
1593 .equals returns True if two Datasets have the same values, dimensions, and coordinates. .broadcast_equals returns True if the
1594 results of broadcasting two Datasets against each other have the same values, dimensions, and coordinates.
1595
1596 >>> a.equals(b)
1597 False
1598
1599 >>> a.broadcast_equals(b)
1600 True
1601
1602 >>> a2, b2 = xr.broadcast(a, b)
1603 >>> a2.equals(b2)
1604 True
1605
1606 See Also
1607 --------

Callers 8

test_broadcast_equalsMethod · 0.95
test_broadcast_equalsMethod · 0.95
test_equals_failuresMethod · 0.45
test_broadcast_equalsMethod · 0.45
test_broadcast_equalsMethod · 0.45

Calls 1

_all_compatMethod · 0.95

Tested by 8

test_broadcast_equalsMethod · 0.76
test_broadcast_equalsMethod · 0.76
test_equals_failuresMethod · 0.36
test_broadcast_equalsMethod · 0.36
test_broadcast_equalsMethod · 0.36