Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to mypy action v0.15.0 #257

Merged
merged 9 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
uses: ASFHyP3/actions/.github/workflows/[email protected]

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

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions Job or Workflow does not set permissions
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 4 additions & 3 deletions src/asf_tools/vector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections.abc import Iterator
from pathlib import Path

from osgeo import ogr
Expand All @@ -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):
Expand Down
Empty file added tests/__init__.py
Empty file.
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)
Loading