From 047851d6cf989833ae5503437bbf76be6ef17210 Mon Sep 17 00:00:00 2001 From: snowman2 Date: Fri, 22 Dec 2023 09:30:25 -0600 Subject: [PATCH] DEP: Support Python 3.10-3.12 --- .github/workflows/build_docs.yaml | 4 +-- .github/workflows/release.yaml | 2 +- .github/workflows/tests.yaml | 18 +++++------ CONTRIBUTING.rst | 2 +- Dockerfile | 2 +- appveyor.yml | 2 +- mypy.ini | 2 +- rioxarray/_io.py | 54 ++++++++++++++++--------------- setup.cfg | 4 +-- 9 files changed, 46 insertions(+), 44 deletions(-) diff --git a/.github/workflows/build_docs.yaml b/.github/workflows/build_docs.yaml index 079d2160..027dfd7c 100644 --- a/.github/workflows/build_docs.yaml +++ b/.github/workflows/build_docs.yaml @@ -23,7 +23,7 @@ jobs: - name: Setup Conda uses: s-weigand/setup-conda@v1 with: - python-version: 3.9 + python-version: 3.10 conda-channels: conda-forge - name: Install and Build @@ -31,7 +31,7 @@ jobs: run: | conda config --prepend channels conda-forge conda config --set channel_priority strict - conda create -n docs python=3.9 rasterio xarray scipy pyproj pandoc + conda create -n docs python=3.10 rasterio xarray scipy pyproj pandoc source activate docs python -m pip install -e .[doc] sphinx-build -b html docs/ docs/_build/ diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e24045d7..89bb09bd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '3.10' - name: Install dependencies run: | diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c7eeee96..5676ddc1 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -32,26 +32,26 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.9', '3.10', '3.11'] + python-version: ['3.10', '3.11', '3.12'] rasterio-version: [''] xarray-version: [''] pandas-version: [''] run-with-scipy: ['YES'] gdal-version: ['3.6.4'] include: - - python-version: '3.9' + - python-version: '3.10' rasterio-version: '' xarray-version: '==0.17' pandas-version: '<2' run-with-scipy: 'YES' gdal-version: '3.4.3' - - python-version: '3.9' + - python-version: '3.10' rasterio-version: '==1.2.1' xarray-version: '' pandas-version: '' run-with-scipy: 'YES' gdal-version: '3.5.3' - - python-version: '3.9' + - python-version: '3.10' rasterio-version: '' xarray-version: '' pandas-version: '' @@ -108,7 +108,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['3.9', '3.10', '3.11'] + python-version: ['3.10', '3.11', '3.12'] rasterio-version: ['*'] xarray-version: ['*'] run-with-scipy: ['YES'] @@ -142,7 +142,7 @@ jobs: conda info - name: pylint - if: matrix.python-version == '3.9' + if: matrix.python-version == '3.10' shell: bash run: | source activate test @@ -150,7 +150,7 @@ jobs: - name: mypy shell: bash - if: matrix.python-version == '3.9' + if: matrix.python-version == '3.10' run: | source activate test mypy rioxarray/ @@ -181,7 +181,7 @@ jobs: - name: Setup Conda uses: s-weigand/setup-conda@v1 with: - python-version: 3.9 + python-version: 3.10 conda-channels: conda-forge - name: Install Env @@ -189,7 +189,7 @@ jobs: run: | conda config --prepend channels conda-forge conda config --set channel_priority strict - conda create -n test python=3.9 proj libgdal cython netcdf4 + conda create -n test python=3.10 proj libgdal cython netcdf4 source activate test python -m pip install \ --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \ diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 15178659..498d8a86 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -135,7 +135,7 @@ Before you submit a pull request, check that it meets these guidelines: 2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. -3. The pull request should work for Python 3.9-3.11. +3. The pull request should work for Python 3.10-3.12. Tips ---- diff --git a/Dockerfile b/Dockerfile index e8f81986..31eb4ab4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ ARG GDAL=ubuntu-full-3.6.4 FROM ghcr.io/osgeo/gdal:${GDAL} -ARG PYTHON_VERSION="3.9" +ARG PYTHON_VERSION="3.10" ENV LANG="C.UTF-8" ENV LC_ALL="C.UTF-8" ENV PIP_NO_BINARY="rasterio" diff --git a/appveyor.yml b/appveyor.yml index 03f37610..c8449fed 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,7 +4,7 @@ environment: matrix: - - PYTHON_VERSION: "3.9" + - PYTHON_VERSION: "3.10" MINICONDA: "C:\\Miniconda3-x64" install: diff --git a/mypy.ini b/mypy.ini index 2df744a3..2857a7a9 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,5 +1,5 @@ [mypy] -python_version = 3.9 +python_version = 3.10 [mypy-affine] ignore_missing_imports = True diff --git a/rioxarray/_io.py b/rioxarray/_io.py index 81911bce..42a45b42 100644 --- a/rioxarray/_io.py +++ b/rioxarray/_io.py @@ -306,14 +306,14 @@ def __init__( self.mask_and_scale = mask_and_scale # cannot save riods as an attribute: this would break pickleability - riods = _ensure_warped_vrt(manager.acquire(), vrt_params) - self.vrt_params = vrt_params - self._shape = (riods.count, riods.height, riods.width) - - self._dtype = None - self._unsigned_dtype = None - self._fill_value = riods.nodata - dtypes = riods.dtypes + with _ensure_warped_vrt(manager.acquire(), vrt_params) as riods: + self.vrt_params = vrt_params + self._shape = (riods.count, riods.height, riods.width) + + self._dtype = None + self._unsigned_dtype = None + self._fill_value = riods.nodata + dtypes = riods.dtypes if not numpy.all(numpy.asarray(dtypes) == dtypes[0]): raise ValueError("All bands should have the same dtype") @@ -424,26 +424,28 @@ def _getitem(self, key): out = numpy.zeros(shape, dtype=self.dtype) else: with self.lock: - riods = _ensure_warped_vrt( + with _ensure_warped_vrt( self.manager.acquire(needs_lock=False), self.vrt_params - ) - out = riods.read(band_key, window=window, masked=self.masked) - if self._unsigned_dtype is not None: - out = out.astype(self._unsigned_dtype) - if self.masked: - out = numpy.ma.filled(out.astype(self.dtype), self.fill_value) - if self.mask_and_scale: - if not isinstance(band_key, Iterable): - out = ( - out * riods.scales[band_key - 1] - + riods.offsets[band_key - 1] - ) - else: - for iii, band_iii in enumerate(numpy.atleast_1d(band_key) - 1): - out[iii] = ( - out[iii] * riods.scales[band_iii] - + riods.offsets[band_iii] + ) as riods: + out = riods.read(band_key, window=window, masked=self.masked) + if self._unsigned_dtype is not None: + out = out.astype(self._unsigned_dtype) + if self.masked: + out = numpy.ma.filled(out.astype(self.dtype), self.fill_value) + if self.mask_and_scale: + if not isinstance(band_key, Iterable): + out = ( + out * riods.scales[band_key - 1] + + riods.offsets[band_key - 1] ) + else: + for iii, band_iii in enumerate( + numpy.atleast_1d(band_key) - 1 + ): + out[iii] = ( + out[iii] * riods.scales[band_iii] + + riods.offsets[band_iii] + ) if squeeze_axis: out = numpy.squeeze(out, axis=squeeze_axis) diff --git a/setup.cfg b/setup.cfg index 6f459c0c..c8153807 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,9 +17,9 @@ classifiers = Operating System :: OS Independent Topic :: Scientific/Engineering :: GIS Programming Language :: Python - Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Programming Language :: Python :: 3 Topic :: Software Development :: Libraries :: Python Modules Typing :: Typed @@ -30,7 +30,7 @@ download_url = http://python.org/pypi/rioxarray packages = find: zip_safe = False # https://mypy.readthedocs.io/en/stable/installed_packages.html include_package_data = True -python_requires = >=3.9 +python_requires = >=3.10 install_requires = packaging rasterio>=1.2