diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18d776e..8fb736a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,13 +8,15 @@ on: tags: - '*' pull_request: +env: + LATEST_PY_VERSION: '3.9' jobs: tests: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: ['3.7', '3.8', '3.9'] steps: - uses: actions/checkout@v2 @@ -28,23 +30,22 @@ jobs: python -m pip install --upgrade pip python -m pip install .["test"] - - name: Run test - run: python -m pytest --cov rio_stac --cov-report xml --cov-report term-missing - - # Run pre-commit (only for python-3.8) - name: run pre-commit - if: matrix.python-version == 3.8 + if: ${{ matrix.python-version == env.LATEST_PY_VERSION }} run: | python -m pip install pre-commit pre-commit run --all-files + - name: Run test + run: python -m pytest --cov rio_stac --cov-report xml --cov-report term-missing + - name: Upload Results - if: success() + if: ${{ matrix.python-version == env.LATEST_PY_VERSION }} uses: codecov/codecov-action@v1 with: file: ./coverage.xml flags: unittests - name: ${{ matrix.platform }}-${{ matrix.tox-env }} + name: ${{ matrix.python-version }} fail_ci_if_error: false publish: diff --git a/CHANGES.md b/CHANGES.md index dfc39c1..4d175cb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +## 0.4.1 (2022-04-26) + +* handle `nan/inf` values to avoid `numpy.histogram` issue (https://github.com/developmentseed/rio-stac/pull/32) + ## 0.4.0 (2022-03-29) * Switch to `pyproject.toml` to simplify setup. diff --git a/rio_stac/stac.py b/rio_stac/stac.py index 142cc6e..0011166 100644 --- a/rio_stac/stac.py +++ b/rio_stac/stac.py @@ -86,6 +86,8 @@ def get_projection_info( def _get_stats(arr: numpy.ma.MaskedArray, **kwargs: Any) -> Dict: """Calculate array statistics.""" + # Avoid non masked nan/inf values + numpy.ma.fix_invalid(arr, copy=False) sample, edges = numpy.histogram(arr[~arr.mask]) return { "statistics": { diff --git a/tests/fixtures/dataset_nodata_and_nan.tif b/tests/fixtures/dataset_nodata_and_nan.tif new file mode 100644 index 0000000..0a5c15d Binary files /dev/null and b/tests/fixtures/dataset_nodata_and_nan.tif differ diff --git a/tests/test_create_item.py b/tests/test_create_item.py index 73d36ff..15e263b 100644 --- a/tests/test_create_item.py +++ b/tests/test_create_item.py @@ -18,6 +18,8 @@ @pytest.mark.parametrize( "file", [ + "dataset_nodata_nan.tif", + "dataset_nodata_and_nan.tif", "dataset_cog.tif", "dataset_gdalcog.tif", "dataset_geo.tif",