diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 5c73689..9fc7ee0 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -11,4 +11,4 @@ jobs: uses: ASFHyP3/actions/.github/workflows/reusable-ruff.yml@v0.12.0 call-mypy-workflow: - uses: ASFHyP3/actions/.github/workflows/reusable-mypy.yml@v0.14.0 + uses: ASFHyP3/actions/.github/workflows/reusable-mypy.yml@v0.15.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 87e2c3a..819f30d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/) and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.8.3] + +### Changed +- Upgraded the `reusable-mypy` action to [v0.15.0](https://github.com/ASFHyP3/actions/releases/tag/v0.15.0). + ## [0.8.2] ### Added diff --git a/environment.yml b/environment.yml index 6d64652..2542546 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - pytest-cov # For running - astropy - - boto3 + - boto3<1.36.0 # FIXME: remove top pin when tests no longer fail - fiona - gdal>=3.7 - geopandas diff --git a/pyproject.toml b/pyproject.toml index 880ebfa..909983b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,4 +112,7 @@ warn_unused_ignores = true warn_unreachable = true strict_equality = true check_untyped_defs = true -explicit_package_bases = true +install_types = true +non_interactive = true +pretty = true +disable_error_code = ["import-untyped"] diff --git a/src/asf_tools/vector.py b/src/asf_tools/vector.py index 831170c..a549f85 100644 --- a/src/asf_tools/vector.py +++ b/src/asf_tools/vector.py @@ -1,4 +1,3 @@ -from collections.abc import Iterator from pathlib import Path from osgeo import ogr @@ -13,14 +12,16 @@ 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): diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/hydrosar/test_flood_map.py b/tests/hydrosar/test_flood_map.py index 72b0198..813ee8c 100644 --- a/tests/hydrosar/test_flood_map.py +++ b/tests/hydrosar/test_flood_map.py @@ -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) diff --git a/tests/test_raster.py b/tests/test_raster.py index 6cdef25..27ece39 100644 --- a/tests/test_raster.py +++ b/tests/test_raster.py @@ -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( @@ -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, @@ -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])) diff --git a/tests/test_tile.py b/tests/test_tile.py index 9a8b80a..1cbf02c 100644 --- a/tests/test_tile.py +++ b/tests/test_tile.py @@ -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( [ @@ -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)) @@ -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( [ @@ -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)