Skip to content

Commit 7fdfcb2

Browse files
committed
Revert "Do not attempt to broadcast when global option arithmetic_broadcast=False (pydata#8784)"
This reverts commit 11f89ec.
1 parent 80fb5f7 commit 7fdfcb2

File tree

5 files changed

+0
-61
lines changed

5 files changed

+0
-61
lines changed

doc/whats-new.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ v2024.03.0 (unreleased)
2323
New Features
2424
~~~~~~~~~~~~
2525

26-
- Do not broadcast in arithmetic operations when global option ``arithmetic_broadcast=False``
27-
(:issue:`6806`, :pull:`8784`).
28-
By `Etienne Schalk <https://github.com/etienneschalk>`_ and `Deepak Cherian <https://github.com/dcherian>`_.
2926
- Add the ``.oindex`` property to Explicitly Indexed Arrays for orthogonal indexing functionality. (:issue:`8238`, :pull:`8750`)
3027
By `Anderson Banihirwe <https://github.com/andersy005>`_.
3128

xarray/core/options.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
]
3535

3636
class T_Options(TypedDict):
37-
arithmetic_broadcast: bool
3837
arithmetic_join: Literal["inner", "outer", "left", "right", "exact"]
3938
cmap_divergent: str | Colormap
4039
cmap_sequential: str | Colormap
@@ -60,7 +59,6 @@ class T_Options(TypedDict):
6059

6160

6261
OPTIONS: T_Options = {
63-
"arithmetic_broadcast": True,
6462
"arithmetic_join": "inner",
6563
"cmap_divergent": "RdBu_r",
6664
"cmap_sequential": "viridis",
@@ -94,7 +92,6 @@ def _positive_integer(value: int) -> bool:
9492

9593

9694
_VALIDATORS = {
97-
"arithmetic_broadcast": lambda value: isinstance(value, bool),
9895
"arithmetic_join": _JOIN_OPTIONS.__contains__,
9996
"display_max_rows": _positive_integer,
10097
"display_values_threshold": _positive_integer,

xarray/core/variable.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,16 +2871,6 @@ def broadcast_variables(*variables: Variable) -> tuple[Variable, ...]:
28712871

28722872

28732873
def _broadcast_compat_data(self, other):
2874-
if not OPTIONS["arithmetic_broadcast"]:
2875-
if (isinstance(other, Variable) and self.dims != other.dims) or (
2876-
is_duck_array(other) and self.ndim != other.ndim
2877-
):
2878-
raise ValueError(
2879-
"Broadcasting is necessary but automatic broadcasting is disabled via "
2880-
"global option `'arithmetic_broadcast'`. "
2881-
"Use `xr.set_options(arithmetic_broadcast=True)` to enable automatic broadcasting."
2882-
)
2883-
28842874
if all(hasattr(other, attr) for attr in ["dims", "data", "shape", "encoding"]):
28852875
# `other` satisfies the necessary Variable API for broadcast_variables
28862876
new_self, new_other = _broadcast_compat_variables(self, other)

xarray/tests/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ def _importorskip(
8989
has_pynio, requires_pynio = _importorskip("Nio")
9090
has_cftime, requires_cftime = _importorskip("cftime")
9191
has_dask, requires_dask = _importorskip("dask")
92-
with warnings.catch_warnings():
93-
warnings.filterwarnings(
94-
"ignore",
95-
message="The current Dask DataFrame implementation is deprecated.",
96-
category=DeprecationWarning,
97-
)
98-
has_dask_expr, requires_dask_expr = _importorskip("dask_expr")
9992
has_bottleneck, requires_bottleneck = _importorskip("bottleneck")
10093
has_rasterio, requires_rasterio = _importorskip("rasterio")
10194
has_zarr, requires_zarr = _importorskip("zarr")

xarray/tests/test_dataarray.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
requires_bottleneck,
5252
requires_cupy,
5353
requires_dask,
54-
requires_dask_expr,
5554
requires_iris,
5655
requires_numexpr,
5756
requires_pint,
@@ -3204,42 +3203,6 @@ def test_align_str_dtype(self) -> None:
32043203
assert_identical(expected_b, actual_b)
32053204
assert expected_b.x.dtype == actual_b.x.dtype
32063205

3207-
def test_broadcast_on_vs_off_global_option_different_dims(self) -> None:
3208-
xda_1 = xr.DataArray([1], dims="x1")
3209-
xda_2 = xr.DataArray([1], dims="x2")
3210-
3211-
with xr.set_options(arithmetic_broadcast=True):
3212-
expected_xda = xr.DataArray([[1.0]], dims=("x1", "x2"))
3213-
actual_xda = xda_1 / xda_2
3214-
assert_identical(actual_xda, expected_xda)
3215-
3216-
with xr.set_options(arithmetic_broadcast=False):
3217-
with pytest.raises(
3218-
ValueError,
3219-
match=re.escape(
3220-
"Broadcasting is necessary but automatic broadcasting is disabled via "
3221-
"global option `'arithmetic_broadcast'`. "
3222-
"Use `xr.set_options(arithmetic_broadcast=True)` to enable automatic broadcasting."
3223-
),
3224-
):
3225-
xda_1 / xda_2
3226-
3227-
@pytest.mark.parametrize("arithmetic_broadcast", [True, False])
3228-
def test_broadcast_on_vs_off_global_option_same_dims(
3229-
self, arithmetic_broadcast: bool
3230-
) -> None:
3231-
# Ensure that no error is raised when arithmetic broadcasting is disabled,
3232-
# when broadcasting is not needed. The two DataArrays have the same
3233-
# dimensions of the same size.
3234-
xda_1 = xr.DataArray([1], dims="x")
3235-
xda_2 = xr.DataArray([1], dims="x")
3236-
expected_xda = xr.DataArray([2.0], dims=("x",))
3237-
3238-
with xr.set_options(arithmetic_broadcast=arithmetic_broadcast):
3239-
assert_identical(xda_1 + xda_2, expected_xda)
3240-
assert_identical(xda_1 + np.array([1.0]), expected_xda)
3241-
assert_identical(np.array([1.0]) + xda_1, expected_xda)
3242-
32433206
def test_broadcast_arrays(self) -> None:
32443207
x = DataArray([1, 2], coords=[("a", [-1, -2])], name="x")
32453208
y = DataArray([1, 2], coords=[("b", [3, 4])], name="y")
@@ -3418,7 +3381,6 @@ def test_to_dataframe_0length(self) -> None:
34183381
assert len(actual) == 0
34193382
assert_array_equal(actual.index.names, list("ABC"))
34203383

3421-
@requires_dask_expr
34223384
@requires_dask
34233385
def test_to_dask_dataframe(self) -> None:
34243386
arr_np = np.arange(3 * 4).reshape(3, 4)

0 commit comments

Comments
 (0)