Skip to content

Commit

Permalink
fix mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jtherrmann committed Jan 18, 2025
1 parent d7dc3f6 commit 30dff60
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/asf_tools/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def get_features(vector_path: str | Path) -> list[ogr.Feature]:
return [feature for feature in layer]


def get_property_values_for_intersecting_features(geometry: ogr.Geometry, features: Iterator) -> bool:
def get_property_values_for_intersecting_features(geometry: ogr.Geometry, features: list[ogr.Feature]) -> bool:
for feature in features:
if feature.GetGeometryRef().Intersects(geometry):
return True
return False


def intersecting_feature_properties(geometry: ogr.Geometry, features: Iterator, feature_property: str) -> list[str]:
def intersecting_feature_properties(geometry: ogr.Geometry, features: list[ogr.Feature], feature_property: str) -> list[str]:
property_values = []
for feature in features:
if feature.GetGeometryRef().Intersects(geometry):
Expand Down
2 changes: 1 addition & 1 deletion tests/hydrosar/test_flood_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_get_waterbody():

def test_logstat():
arr = [10, 100, 1000, 10000, 100000]
logstd = flood_map.logstat(arr)
logstd = flood_map.logstat(arr) # type: ignore[arg-type]

assert np.isclose(logstd, 25.95455351947008)

Expand Down
8 changes: 6 additions & 2 deletions tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def test_convert_scale():

a = np.array([-10, -5, 0, 5, 10])
with pytest.raises(ValueError):
_ = raster.convert_scale(a, 'power', 'foo')
_ = raster.convert_scale(a, 'power', 'foo') # type: ignore[arg-type]
with pytest.raises(ValueError):
_ = raster.convert_scale(a, 'bar', 'amplitude')
_ = raster.convert_scale(a, 'bar', 'amplitude') # type: ignore[arg-type]

with pytest.warns(UserWarning):
assert np.allclose(
Expand All @@ -50,6 +50,8 @@ def test_convert_scale():
def test_convert_scale_masked_arrays():
masked_array: np.ma.MaskedArray = np.ma.MaskedArray([-1, 0, 1, 4, 9], mask=[False, False, False, False, False])
c = raster.convert_scale(masked_array, 'power', 'db')

assert isinstance(c, np.ma.MaskedArray)
assert np.allclose(c.mask, [True, True, False, False, False])
assert np.allclose(
c,
Expand All @@ -60,6 +62,8 @@ def test_convert_scale_masked_arrays():
)

a = raster.convert_scale(c, 'db', 'power')

assert isinstance(a, np.ma.MaskedArray)
assert np.allclose(a.mask, [True, True, False, False, False])
assert np.allclose(a, np.ma.MaskedArray([-1, 0, 1, 4, 9], mask=[True, True, False, False, False]))

Expand Down
9 changes: 7 additions & 2 deletions tests/test_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_tile_masked_array():
a = np.array([[0, 0, 1, 1], [0, 0, 1, 1], [2, 2, 3, 3], [2, 2, 3, 3]])

with pytest.raises(AttributeError):
_ = tile.tile_array(a, tile_shape=(2, 2)).mask
_ = tile.tile_array(a, tile_shape=(2, 2)).mask # type: ignore[attr-defined]

m = np.array(
[
Expand Down Expand Up @@ -86,6 +86,7 @@ def test_untile_array():
]
)

assert len(a.shape) == 2
assert np.all(a == tile.untile_array(tile.tile_array(a, tile_shape=(2, 2)), array_shape=a.shape))
assert np.all(a == tile.untile_array(tile.tile_array(a, tile_shape=(4, 4), pad_value=9), array_shape=a.shape))
assert np.all(a == tile.untile_array(tile.tile_array(a, tile_shape=(2, 4), pad_value=9), array_shape=a.shape))
Expand All @@ -107,8 +108,9 @@ def test_untile_array():
def test_untile_masked_array():
a = np.array([[0, 0, 1, 1], [0, 0, 1, 1], [2, 2, 3, 3], [2, 2, 3, 3]])

assert len(a.shape) == 2
with pytest.raises(AttributeError):
_ = tile.untile_array(tile.tile_array(a, tile_shape=(2, 2)), array_shape=a.shape).mask
_ = tile.untile_array(tile.tile_array(a, tile_shape=(2, 2)), array_shape=a.shape).mask # type: ignore[attr-defined]

m = np.array(
[
Expand All @@ -122,9 +124,12 @@ def test_untile_masked_array():
ma: np.ma.MaskedArray = np.ma.MaskedArray(a, mask=m)
untiled = tile.untile_array(tile.tile_array(ma.copy(), tile_shape=(2, 2)), array_shape=a.shape)

assert isinstance(untiled, np.ma.MaskedArray)
assert np.all(ma == untiled)
assert np.all(ma.mask == untiled.mask)

untiled = tile.untile_array(tile.tile_array(ma.copy(), tile_shape=(3, 3), pad_value=4), array_shape=a.shape)

assert isinstance(untiled, np.ma.MaskedArray)
assert np.all(ma == untiled)
assert np.all(ma.mask == untiled.mask)

0 comments on commit 30dff60

Please sign in to comment.