Skip to content

Commit

Permalink
Apply ruff/flake8-simplify rule SIM401 (#9749)
Browse files Browse the repository at this point in the history
SIM401 Use `.get()` instead of an `if` block
  • Loading branch information
DimitriPapadopoulos authored Nov 8, 2024
1 parent 61596a7 commit 7e2e76e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion xarray/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def cf_encoder(variables: T_Variables, attributes: T_Attrs):

# Remove attrs from bounds variables (issue #2921)
for var in new_vars.values():
bounds = var.attrs["bounds"] if "bounds" in var.attrs else None
bounds = var.attrs.get("bounds")
if bounds and bounds in new_vars:
# see http://cfconventions.org/cf-conventions/cf-conventions.html#cell-boundaries
for attr in [
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def _wrapper(
# unchunked dimensions in the input have one chunk in the result
# output can have new dimensions with exactly one chunk
key: tuple[Any, ...] = (gname_l,) + tuple(
chunk_index[dim] if dim in chunk_index else 0 for dim in variable.dims
chunk_index.get(dim, 0) for dim in variable.dims
)

# We're adding multiple new layers to the graph:
Expand Down
4 changes: 2 additions & 2 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,10 +1147,10 @@ def _pad_options_dim_to_index(

if fill_with_shape:
return [
(n, n) if d not in pad_option else pad_option[d]
pad_option.get(d, (n, n))
for d, n in zip(self.dims, self.data.shape, strict=True)
]
return [(0, 0) if d not in pad_option else pad_option[d] for d in self.dims]
return [pad_option.get(d, (0, 0)) for d in self.dims]

def pad(
self,
Expand Down

0 comments on commit 7e2e76e

Please sign in to comment.