Skip to content

Commit

Permalink
Apply ruff/Perflint rule PERF403
Browse files Browse the repository at this point in the history
PERF403 Use a dictionary comprehension instead of a for-loop
  • Loading branch information
DimitriPapadopoulos committed Nov 7, 2024
1 parent a2ce696 commit d09d594
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 1 addition & 5 deletions xarray/backends/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ def get_variables(self):
return self._variables

def get_dimensions(self):
dims = {}
for v in self._variables.values():
for d, s in v.dims.items():
dims[d] = s
return dims
return {d: s for v in self._variables.values() for d, s in v.dims.items()}

def prepare_variable(self, k, v, *args, **kwargs):
new_var = Variable(v.dims, np.empty_like(v), v.attrs)
Expand Down
9 changes: 5 additions & 4 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9364,10 +9364,11 @@ def pad(
# keep indexes that won't be affected by pad and drop all other indexes
xindexes = self.xindexes
pad_dims = set(pad_width)
indexes = {}
for k, idx in xindexes.items():
if not pad_dims.intersection(xindexes.get_all_dims(k)):
indexes[k] = idx
indexes = {
k: idx
for k, idx in xindexes.items()
if not pad_dims.intersection(xindexes.get_all_dims(k))
}

for name, var in self.variables.items():
var_pad_width = {k: v for k, v in pad_width.items() if k in var.dims}
Expand Down

0 comments on commit d09d594

Please sign in to comment.