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

Drop Python 3.8 support #1246

Merged
merged 14 commits into from
Apr 16, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
pip install -r requirements/style.txt
pip list
- name: Run pyupgrade checks
run: pyupgrade --py38-plus $(find . -path ./docs/src -prune -o -name "*.py" -print)
run: pyupgrade --py39-plus $(find . -path ./docs/src -prune -o -name "*.py" -print)
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.9', '3.10']
steps:
- name: Clone repo
uses: actions/[email protected]
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
- name: Set up python
uses: actions/[email protected]
with:
python-version: '3.8'
python-version: '3.9'
- name: Cache dependencies
uses: actions/[email protected]
id: cache
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
args: [--py39-plus]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
Expand Down
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ version: 2

# Set the version of Python
build:
os: ubuntu-20.04
os: ubuntu-22.04
tools:
python: "3.9"
python: "3.10"

# Configuration of the Python environment to be used
python:
Expand Down
6 changes: 3 additions & 3 deletions docs/user/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ For example, if you add a new dataset in ``torchgeo/datasets/foo.py``, you'll ne

$ pytest --cov=torchgeo/datasets --cov-report=term-missing tests/datasets/test_foo.py
========================= test session starts =========================
platform darwin -- Python 3.8.11, pytest-6.2.4, py-1.9.0, pluggy-0.13.0
platform darwin -- Python 3.10.11, pytest-6.2.4, py-1.9.0, pluggy-0.13.0
rootdir: ~/torchgeo, configfile: pyproject.toml
plugins: mock-1.11.1, anyio-3.2.1, cov-2.8.1, nbmake-0.5
collected 7 items

tests/datasets/test_foo.py ....... [100%]

---------- coverage: platform darwin, python 3.8.11-final-0 -----------
---------- coverage: platform darwin, python 3.10.11-final-0 -----------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a find and replace artifact?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, just noticed it while grepping around and figured we should pretend it was run on a supported version of Python.

Name Stmts Miss Cover Missing
-----------------------------------------------------------------------
torchgeo/datasets/__init__.py 26 0 100%
Expand Down Expand Up @@ -103,7 +103,7 @@ All of these tools should be used from the root of the project to ensure that ou

$ black .
$ isort .
$ pyupgrade --py38-plus $(find . -name "*.py")
$ pyupgrade --py39-plus $(find . -name "*.py")


Flake8, pydocstyle, and mypy won't format your code for you, but they will warn you about potential issues with your code or docstrings:
Expand Down
26 changes: 13 additions & 13 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ channels:
- conda-forge
dependencies:
- einops>=0.3
- fiona>=1.8.12
- h5py>=2.9
- matplotlib>=3.3
- numpy>=1.17.3
- fiona>=1.8.19
- h5py>=3
- matplotlib>=3.3.3
- numpy>=1.19.3
- pip
- pycocotools>=2.0.1
- pyproj>=2.4.1
- python>=3.8
- pyproj>=3
- python>=3.9
- pytorch>=1.12
- pyvista>=0.25.2
- rarfile>=4
- rasterio>=1.1.1
- shapely>=1.7
- rasterio>=1.2
- shapely>=1.7.1
- torchvision>=0.13
- pip:
- black[jupyter]>=21.8
Expand All @@ -30,18 +30,18 @@ dependencies:
- nbmake>=1.3.3
- nbsphinx>=0.8.5
- omegaconf>=2.1
- opencv-python>=4.1.2
- pandas>=0.25.2
- pillow>=6.2.1
- opencv-python>=4.4.0.46
- pandas>=1.1.3
- pillow>=8
- pydocstyle[toml]>=6.1
- pytest>=6.1.2
- pytest-cov>=2.4
- git+https://github.com/pytorch/pytorch_sphinx_theme
- pyupgrade>=2.4
- pyupgrade>=2.8
- radiant-mlhub>=0.3
- rtree>=1
- scikit-image>=0.18
- scikit-learn>=0.22
- scikit-learn>=0.24
- scipy>=1.6.2
- segmentation-models-pytorch>=0.2
- setuptools>=42
Expand Down
4 changes: 2 additions & 2 deletions evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import argparse
import csv
import os
from typing import Any, Dict, Union, cast
from typing import Any, Union, cast

import lightning.pytorch as pl
import torch
Expand Down Expand Up @@ -155,7 +155,7 @@ def main(args: argparse.Namespace) -> None:
dm.setup("validate")

# Record model hyperparameters
hparams = cast(Dict[str, Union[str, float]], model.hparams)
hparams = cast(dict[str, Union[str, float]], model.hparams)
if issubclass(TASK, ClassificationTask):
val_row = {
"split": "val",
Expand Down
58 changes: 29 additions & 29 deletions experiments/download_ssl4eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from collections import OrderedDict
from datetime import date, datetime, timedelta
from multiprocessing.dummy import Lock, Pool
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Optional

import ee
import numpy as np
Expand Down Expand Up @@ -79,7 +79,7 @@ def date2str(date: datetime) -> str:
return date.strftime("%Y-%m-%d")


def get_period(date: datetime, days: int = 5) -> Tuple[str, str]:
def get_period(date: datetime, days: int = 5) -> tuple[str, str]:
date1 = date - timedelta(days=days / 2)
date2 = date + timedelta(days=days / 2)
return date2str(date1), date2str(date2)
Expand Down Expand Up @@ -121,7 +121,7 @@ def get_collection_s1() -> ee.ImageCollection:


def filter_collection(
collection: ee.ImageCollection, coords: List[float], period: Tuple[str, str]
collection: ee.ImageCollection, coords: list[float], period: tuple[str, str]
) -> ee.ImageCollection:
filtered = collection
if period is not None:
Expand All @@ -137,7 +137,7 @@ def filter_collection(


def filter_collection_s1(
collection: ee.ImageCollection, coords: List[float], period: Tuple[str, str]
collection: ee.ImageCollection, coords: list[float], period: tuple[str, str]
) -> ee.ImageCollection:
filtered = collection
if period is not None:
Expand All @@ -161,7 +161,7 @@ def filter_collection_s1(


def center_crop(
img: np.ndarray[Any, np.dtype[Any]], out_size: Tuple[int, int]
img: np.ndarray[Any, np.dtype[Any]], out_size: tuple[int, int]
) -> np.ndarray[Any, np.dtype[Any]]:
image_height, image_width = img.shape[:2]
crop_height, crop_width = out_size
Expand All @@ -171,8 +171,8 @@ def center_crop(


def adjust_coords(
coords: List[List[float]], old_size: Tuple[int, int], new_size: Tuple[int, int]
) -> List[List[float]]:
coords: list[list[float]], old_size: tuple[int, int], new_size: tuple[int, int]
) -> list[list[float]]:
xres = (coords[1][0] - coords[0][0]) / old_size[1]
yres = (coords[0][1] - coords[1][1]) / old_size[0]
xoff = int((old_size[1] - new_size[1] + 1) * 0.5)
Expand All @@ -192,11 +192,11 @@ def get_properties(image: ee.Image) -> Any:

def get_patch_s1(
collection: ee.ImageCollection,
center_coord: List[float],
center_coord: list[float],
radius: float,
bands: List[str],
crop: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
bands: list[str],
crop: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
image = collection.sort("system:time_start", False).first() # get most recent
region = (
ee.Geometry.Point(center_coord).buffer(radius).bounds()
Expand Down Expand Up @@ -233,11 +233,11 @@ def get_patch_s1(

def get_patch_s2(
collection: ee.ImageCollection,
center_coord: List[float],
center_coord: list[float],
radius: float,
bands: Optional[List[str]] = None,
crop: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
bands: Optional[list[str]] = None,
crop: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
if bands is None:
bands = RGB_BANDS

Expand Down Expand Up @@ -277,18 +277,18 @@ def get_patch_s2(

def get_random_patches_match(
idx: int,
collections: Dict[str, Any],
bands: Dict[str, Any],
crops: Dict[str, Any],
dates: List[Any],
collections: dict[str, Any],
bands: dict[str, Any],
crops: dict[str, Any],
dates: list[Any],
radius: int,
debug: bool = False,
match_coords: Dict[str, Any] = {},
) -> Tuple[
Optional[List[Dict[str, Any]]],
Optional[List[Dict[str, Any]]],
Optional[List[Dict[str, Any]]],
List[float],
match_coords: dict[str, Any] = {},
) -> tuple[
Optional[list[dict[str, Any]]],
Optional[list[dict[str, Any]]],
Optional[list[dict[str, Any]]],
list[float],
]:
# (lon,lat) of idx patch
coords = match_coords[str(idx)]
Expand Down Expand Up @@ -343,7 +343,7 @@ def get_random_patches_match(


def save_geotiff(
img: np.ndarray[Any, np.dtype[Any]], coords: List[List[float]], filename: str
img: np.ndarray[Any, np.dtype[Any]], coords: list[list[float]], filename: str
) -> None:
height, width, channels = img.shape
xres = (coords[1][0] - coords[0][0]) / width
Expand All @@ -366,9 +366,9 @@ def save_geotiff(


def save_patch(
raster: Dict[str, Any],
coords: List[List[float]],
metadata: Dict[str, Any],
raster: dict[str, Any],
coords: list[list[float]],
metadata: dict[str, Any],
path: str,
) -> None:
patch_id = metadata["properties"]["system:index"]
Expand Down
3 changes: 1 addition & 2 deletions experiments/run_benchmarks_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import subprocess
import time
from typing import List

EPOCH_SIZE = 4096

Expand All @@ -34,7 +33,7 @@
):
print(f"\n{i}/{total_num_experiments} -- {time.time() - tic}")
tic = time.time()
command: List[str] = [
command: list[str] = [
"python",
"benchmark.py",
"--landsat-root",
Expand Down
3 changes: 1 addition & 2 deletions experiments/run_so2sat_byol_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import subprocess
from multiprocessing import Process, Queue
from typing import List

# list of GPU IDs that we want to use, one job will be started for every ID in the list
GPUS = [0, 1, 2, 3, 3]
Expand All @@ -18,7 +17,7 @@
model_options = ["resnet50"]
lr_options = [1e-4]
loss_options = ["ce"]
weight_options: List[str] = [] # set paths to checkpoint files
weight_options: list[str] = [] # set paths to checkpoint files
bands_options = ["s2"]


Expand Down
7 changes: 3 additions & 4 deletions experiments/sample_ssl4eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import os
import time
import warnings
from typing import Tuple

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -69,7 +68,7 @@ def km2deg(kms: float, radius: float = 6371) -> float:
return kms / (2.0 * radius * np.pi / 360.0)


def sample_point(cities: pd.DataFrame, std: float) -> Tuple[float, float]:
def sample_point(cities: pd.DataFrame, std: float) -> tuple[float, float]:
city = cities.sample()
point = (float(city["lng"]), float(city["lat"]))
std = km2deg(std)
Expand All @@ -78,8 +77,8 @@ def sample_point(cities: pd.DataFrame, std: float) -> Tuple[float, float]:


def create_bbox(
coords: Tuple[float, float], bbox_size_degree: float
) -> Tuple[float, float, float, float]:
coords: tuple[float, float], bbox_size_degree: float
) -> tuple[float, float, float, float]:
lon, lat = coords
bbox = (
lon - bbox_size_degree,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ requires = [
build-backend = "setuptools.build_meta"

[tool.black]
target-version = ["py38", "py39", "py310"]
target-version = ["py39", "py310"]
color = true
skip_magic_trailing_comma = true

Expand All @@ -25,7 +25,7 @@ skip_gitignore = true
color_output = true

[tool.mypy]
python_version = "3.8"
python_version = "3.9"
ignore_missing_imports = true
show_error_codes = true
exclude = "(build|data|dist|docs/src|images|logo|logs|output)/"
Expand Down
Loading