Skip to content

Commit 73e20af

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent bc67fda commit 73e20af

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

xarray/core/variable.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1372,14 +1372,14 @@ def set_dims(self, dim, shape=None):
13721372
# writeable if possible
13731373
expanded_data = self.data
13741374
elif shape is None or all(
1375-
s == 1 for s, e in zip(shape, dim) if e not in self_dims
1375+
s == 1 for s, e in zip(shape, dim, strict=False) if e not in self_dims
13761376
):
13771377
# "Trivial" broadcasting, i.e. simply inserting a new dimension
13781378
# This is typically easier for duck arrays to implement
13791379
# than the full "broadcast_to" semantics
13801380
indexer = (None,) * (len(expanded_dims) - self.ndim) + (...,)
13811381
expanded_data = self.data[indexer]
1382-
else: # elif shape is not None:
1382+
else: # elif shape is not None:
13831383
dims_map = dict(zip(dim, shape, strict=True))
13841384
tmp_shape = tuple(dims_map[d] for d in expanded_dims)
13851385
expanded_data = duck_array_ops.broadcast_to(self._data, tmp_shape)

xarray/tests/test_variable.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
requires_pint,
4646
requires_sparse,
4747
source_ndarray,
48-
InaccessibleArray,
4948
)
5049
from xarray.tests.test_namedarray import NamedArraySubclassobjects
5150

@@ -1667,7 +1666,8 @@ def __getitem__(self, key):
16671666
def __array_function__(self, *args, **kwargs):
16681667
raise NotImplementedError(
16691668
"Not we don't want to use broadcast_to here "
1670-
"https://github.com/pydata/xarray/issues/9462")
1669+
"https://github.com/pydata/xarray/issues/9462"
1670+
)
16711671

16721672
arr = ArrayWithoutBroadcastTo(np.zeros((3, 4)))
16731673
# We should be able to add a new axis without broadcasting
@@ -1680,7 +1680,7 @@ def __array_function__(self, *args, **kwargs):
16801680
assert v_expanded.dims == ("z", "x", "y")
16811681
assert v_expanded.shape == (1, 3, 4)
16821682

1683-
# Explicitely asking for a shape of 1 triggers a different
1683+
# Explicitly asking for a shape of 1 triggers a different
16841684
# codepath in set_dims
16851685
# https://github.com/pydata/xarray/issues/9462
16861686
v_expanded = v.set_dims(["z", "x", "y"], shape=(1, 3, 4))
@@ -1713,7 +1713,6 @@ def __array_function__(self, *args, **kwargs):
17131713
with pytest.raises(NotImplementedError):
17141714
v.set_dims(["z", "x", "y"], shape=(2, 3, 4))
17151715

1716-
17171716
def test_stack(self):
17181717
v = Variable(["x", "y"], [[0, 1], [2, 3]], {"foo": "bar"})
17191718
actual = v.stack(z=("x", "y"))

0 commit comments

Comments
 (0)