Skip to content

Commit

Permalink
Merge pull request #187 from mcflugen/mcflugen/add-flake8-comprehensions
Browse files Browse the repository at this point in the history
Add linters to deltametrics: flake8-comprehensions
  • Loading branch information
mcflugen authored Dec 13, 2024
2 parents 09a164d + 8359596 commit b86eb7b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ repos:
rev: 7.1.1
hooks:
- id: flake8
# additional_dependencies:
additional_dependencies:
# - flake8-bugbear
# - flake8-comprehensions
# - flake8-simplify
- flake8-comprehensions
- flake8-simplify
exclude: ^docs/source/pyplots/guides/.*$

- repo: https://github.com/asottile/pyupgrade
Expand Down
6 changes: 3 additions & 3 deletions deltametrics/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def __getitem__(self, var):
@property
def keys(self):
"""Variable names in file."""
return [var for var in self.dataset.variables]
return list(self.dataset.variables)


class DictionaryIO(BaseIO):
Expand Down Expand Up @@ -364,7 +364,7 @@ def get_known_variables(self):
These variables are pulled from the loaded dataset.
"""
_vars = self.dataset.keys()
self.known_variables = [item for item in _vars]
self.known_variables = list(_vars)

def get_known_coords(self, dimensions):
"""List known coordinates.
Expand Down Expand Up @@ -462,4 +462,4 @@ def __getitem__(self, var):
@property
def keys(self):
"""Variable names in file."""
return [var for var in self.dataset.variables]
return list(self.dataset.variables)
10 changes: 4 additions & 6 deletions deltametrics/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,12 +1594,10 @@ def grab_contour(self, arr, shoremap):
# breakpoint()

# convert contour to the shoreline mask itself
flat_inds = list(
map(
lambda x: np.ravel_multi_index(x, shoremap.shape),
np.round(C).astype(int),
)
)
flat_inds = [
np.ravel_multi_index(x, shoremap.shape)
for x in np.round(C).astype(int)
]
shoremap.flat[flat_inds] = 1

self._contour = C
Expand Down
2 changes: 1 addition & 1 deletion deltametrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _attribute_checker(self, checklist):
else:
att_dict[check] = True

log_list = [value for value in att_dict.values()]
log_list = list(att_dict.values())
log_form = [value for string, value in
zip(log_list, att_dict.keys()) if not string]
if not all(log_list):
Expand Down
16 changes: 8 additions & 8 deletions tests/test_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ def test_circular_default(self):
gmsk.circular(1)
assert gmsk._mask[0, 2] == 0

gmsk2 = GeometricMask(arr, circular=dict(rad1=1))
gmsk2 = GeometricMask(arr, circular={"rad1": 1})
assert np.all(gmsk2.mask == gmsk.mask)

def test_circular_2radii(self):
Expand All @@ -1720,7 +1720,7 @@ def test_circular_2radii(self):
assert np.all(gmsk._mask[:, 0] == 0)
assert np.all(gmsk._mask[-1, :] == 0)

gmsk2 = GeometricMask(arr, circular=dict(rad1=1, rad2=2))
gmsk2 = GeometricMask(arr, circular={"rad1": 1, "rad2": 2})
assert np.all(gmsk2.mask == gmsk.mask)

def test_circular_custom_origin(self):
Expand Down Expand Up @@ -1750,7 +1750,7 @@ def test_circular_custom_origin(self):
assert gmsk.xc == 0
assert gmsk.yc == 3

gmsk2 = GeometricMask(arr, circular=dict(rad1=1, rad2=2, origin=(3, 3)))
gmsk2 = GeometricMask(arr, circular={"rad1": 1, "rad2": 2, "origin": (3, 3)})
assert np.all(gmsk2.mask == gmsk.mask)

def test_strike_one(self):
Expand All @@ -1761,7 +1761,7 @@ def test_strike_one(self):
assert np.all(gmsk._mask[:2, :] == 0)
assert np.all(gmsk._mask[2:, :] == 1)

gmsk2 = GeometricMask(arr, strike=dict(ind1=2))
gmsk2 = GeometricMask(arr, strike={"ind1": 2})
assert np.all(gmsk2.mask == gmsk.mask)

def test_strike_two(self):
Expand All @@ -1773,7 +1773,7 @@ def test_strike_two(self):
assert np.all(gmsk._mask[2:4, :] == 1)
assert np.all(gmsk._mask[4:, :] == 0)

gmsk2 = GeometricMask(arr, strike=dict(ind1=2, ind2=4))
gmsk2 = GeometricMask(arr, strike={"ind1": 2, "ind2": 4})
assert np.all(gmsk2.mask == gmsk.mask)

def test_dip_one(self):
Expand All @@ -1785,7 +1785,7 @@ def test_dip_one(self):
assert np.all(gmsk._mask[:, 0] == 0)
assert np.all(gmsk._mask[:, -1] == 0)

gmsk2 = GeometricMask(arr, dip=dict(ind1=5))
gmsk2 = GeometricMask(arr, dip={"ind1": 5})
assert np.all(gmsk2.mask == gmsk.mask)

def test_dip_two(self):
Expand All @@ -1797,7 +1797,7 @@ def test_dip_two(self):
assert np.all(gmsk._mask[:, 2:4] == 1)
assert np.all(gmsk._mask[:, 4:] == 0)

gmsk2 = GeometricMask(arr, dip=dict(ind1=2, ind2=4))
gmsk2 = GeometricMask(arr, dip={"ind1": 2, "ind2": 4})
assert np.all(gmsk2.mask == gmsk.mask)

def test_angular_half(self):
Expand All @@ -1811,7 +1811,7 @@ def test_angular_half(self):
assert np.all(gmsk._mask[:, :101] == 1)
assert np.all(gmsk._mask[:, 101:] == 0)

gmsk2 = GeometricMask(arr, angular=dict(theta1=theta1, theta2=theta2))
gmsk2 = GeometricMask(arr, angular={"theta1": theta1, "theta2": theta2})
assert np.all(gmsk2.mask == gmsk.mask)

def test_angular_bad_dims(self):
Expand Down

0 comments on commit b86eb7b

Please sign in to comment.