Skip to content

Commit 7e2e76e

Browse files
Apply ruff/flake8-simplify rule SIM401 (#9749)
SIM401 Use `.get()` instead of an `if` block
1 parent 61596a7 commit 7e2e76e

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

xarray/conventions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def cf_encoder(variables: T_Variables, attributes: T_Attrs):
805805

806806
# Remove attrs from bounds variables (issue #2921)
807807
for var in new_vars.values():
808-
bounds = var.attrs["bounds"] if "bounds" in var.attrs else None
808+
bounds = var.attrs.get("bounds")
809809
if bounds and bounds in new_vars:
810810
# see http://cfconventions.org/cf-conventions/cf-conventions.html#cell-boundaries
811811
for attr in [

xarray/core/parallel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def _wrapper(
600600
# unchunked dimensions in the input have one chunk in the result
601601
# output can have new dimensions with exactly one chunk
602602
key: tuple[Any, ...] = (gname_l,) + tuple(
603-
chunk_index[dim] if dim in chunk_index else 0 for dim in variable.dims
603+
chunk_index.get(dim, 0) for dim in variable.dims
604604
)
605605

606606
# We're adding multiple new layers to the graph:

xarray/core/variable.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1147,10 +1147,10 @@ def _pad_options_dim_to_index(
11471147

11481148
if fill_with_shape:
11491149
return [
1150-
(n, n) if d not in pad_option else pad_option[d]
1150+
pad_option.get(d, (n, n))
11511151
for d, n in zip(self.dims, self.data.shape, strict=True)
11521152
]
1153-
return [(0, 0) if d not in pad_option else pad_option[d] for d in self.dims]
1153+
return [pad_option.get(d, (0, 0)) for d in self.dims]
11541154

11551155
def pad(
11561156
self,

0 commit comments

Comments
 (0)