Skip to content

Commit

Permalink
🔧 python 3.10 upgrade (#391)
Browse files Browse the repository at this point in the history
* python 3.10 upgrade

---------

Co-authored-by: Philippe Miron <philippe.miron@dtn.com>
  • Loading branch information
kevinsantana11 and Philippe Miron authored Apr 11, 2024
1 parent a96877b commit c488f0d
Show file tree
Hide file tree
Showing 28 changed files with 231 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.9"]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: 3.9
python-version: 3.10
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: 3.9
python-version: 3.10
- uses: actions/download-artifact@v4
with:
name: releases
Expand Down
3 changes: 1 addition & 2 deletions clouddrift/adapters/andro.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import tempfile
import warnings
from datetime import datetime
from typing import Union

import numpy as np
import pandas as pd
Expand All @@ -35,7 +34,7 @@
ANDRO_VERSION = "2022-03-04"


def to_xarray(tmp_path: Union[str, None] = None):
def to_xarray(tmp_path: str | None = None):
if tmp_path is None:
tmp_path = ANDRO_TMP_PATH
os.makedirs(tmp_path, exist_ok=True)
Expand Down
24 changes: 12 additions & 12 deletions clouddrift/adapters/gdp1h.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import tempfile
import urllib.request
import warnings
from collections.abc import Sequence
from datetime import datetime, timedelta
from typing import Optional, Sequence, Union

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -59,8 +59,8 @@
def download(
url: str,
tmp_path: str,
drifter_ids: Union[list[int], None] = None,
n_random_id: Union[int, None] = None,
drifter_ids: list[int] | None = None,
n_random_id: int | None = None,
):
"""Download individual NetCDF files from the AOML server.
Expand Down Expand Up @@ -523,10 +523,10 @@ def preprocess(index: int, **kwargs) -> xr.Dataset:


def to_raggedarray(
drifter_ids: Optional[list[int]] = None,
n_random_id: Optional[int] = None,
drifter_ids: list[int] | None = None,
n_random_id: int | None = None,
url: str = GDP_DATA_URL,
tmp_path: Optional[str] = None,
tmp_path: str | None = None,
) -> RaggedArray:
"""Download and process individual GDP hourly files and return a RaggedArray
instance with the data.
Expand Down Expand Up @@ -610,11 +610,11 @@ def to_raggedarray(

# set dynamic global attributes
if ra.attrs_global:
ra.attrs_global[
"time_coverage_start"
] = f"{datetime(1970,1,1) + timedelta(seconds=int(np.min(ra.coords['time']))):%Y-%m-%d:%H:%M:%SZ}"
ra.attrs_global[
"time_coverage_end"
] = f"{datetime(1970,1,1) + timedelta(seconds=int(np.max(ra.coords['time']))):%Y-%m-%d:%H:%M:%SZ}"
ra.attrs_global["time_coverage_start"] = (
f"{datetime(1970,1,1) + timedelta(seconds=int(np.min(ra.coords['time']))):%Y-%m-%d:%H:%M:%SZ}"
)
ra.attrs_global["time_coverage_end"] = (
f"{datetime(1970,1,1) + timedelta(seconds=int(np.max(ra.coords['time']))):%Y-%m-%d:%H:%M:%SZ}"
)

return ra
21 changes: 10 additions & 11 deletions clouddrift/adapters/gdp6h.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import tempfile
import urllib.request
import warnings
from typing import Optional, Union

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -39,8 +38,8 @@
def download(
url: str,
tmp_path: str,
drifter_ids: Union[list, None] = None,
n_random_id: Union[int, None] = None,
drifter_ids: list | None = None,
n_random_id: int | None = None,
):
"""Download individual NetCDF files from the AOML server.
Expand Down Expand Up @@ -448,8 +447,8 @@ def preprocess(index: int, **kwargs) -> xr.Dataset:


def to_raggedarray(
drifter_ids: Optional[list[int]] = None,
n_random_id: Optional[int] = None,
drifter_ids: list[int] | None = None,
n_random_id: int | None = None,
tmp_path: str = GDP_TMP_PATH,
) -> RaggedArray:
"""Download and process individual GDP 6-hourly files and return a
Expand Down Expand Up @@ -518,11 +517,11 @@ def to_raggedarray(
)

# update dynamic global attributes
ra.attrs_global[
"time_coverage_start"
] = f"{datetime.datetime(1970,1,1) + datetime.timedelta(seconds=int(np.min(ra.coords['time']))):%Y-%m-%d:%H:%M:%SZ}"
ra.attrs_global[
"time_coverage_end"
] = f"{datetime.datetime(1970,1,1) + datetime.timedelta(seconds=int(np.max(ra.coords['time']))):%Y-%m-%d:%H:%M:%SZ}"
ra.attrs_global["time_coverage_start"] = (
f"{datetime.datetime(1970,1,1) + datetime.timedelta(seconds=int(np.min(ra.coords['time']))):%Y-%m-%d:%H:%M:%SZ}"
)
ra.attrs_global["time_coverage_end"] = (
f"{datetime.datetime(1970,1,1) + datetime.timedelta(seconds=int(np.max(ra.coords['time']))):%Y-%m-%d:%H:%M:%SZ}"
)

return ra
3 changes: 1 addition & 2 deletions clouddrift/adapters/mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import xml.etree.ElementTree as ET
from datetime import datetime
from io import BytesIO
from typing import Tuple

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -79,7 +78,7 @@ def get_dataframes() -> tuple[pd.DataFrame, pd.DataFrame]:
return obs_df, sensors


def get_file_urls(xml: bytes) -> Tuple[list[str], list[str]]:
def get_file_urls(xml: bytes) -> tuple[list[str], list[str]]:
"""Pass the MOSAiC XML string and return the list of filenames and URLs."""
filenames = [
tag.text
Expand Down
6 changes: 3 additions & 3 deletions clouddrift/adapters/subsurface_floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import os
import tempfile
import warnings
from collections.abc import Hashable
from datetime import datetime
from typing import Hashable, List, Union

import numpy as np
import pandas as pd
Expand All @@ -38,7 +38,7 @@ def download(file: str):


def to_xarray(
tmp_path: Union[str, None] = None,
tmp_path: str | None = None,
):
if tmp_path is None:
tmp_path = SUBSURFACE_FLOATS_TMP_PATH
Expand All @@ -49,7 +49,7 @@ def to_xarray(
source_data = scipy.io.loadmat(local_file)

# metadata
meta_variables: List[Hashable] = [
meta_variables: list[Hashable] = [
"expList",
"expName",
"expOrg",
Expand Down
18 changes: 8 additions & 10 deletions clouddrift/adapters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import logging
import os
import traceback
from collections.abc import Callable, Sequence
from datetime import datetime
from io import BufferedIOBase, StringIO
from typing import Callable, Sequence, Tuple, Union

import requests
from requests import Response
Expand Down Expand Up @@ -32,10 +32,10 @@


def download_with_progress(
download_map: Sequence[Tuple[str, Union[BufferedIOBase, str], Union[float, None]]],
show_list_progress: Union[bool, None] = None,
download_map: Sequence[tuple[str, BufferedIOBase | str, float | None]],
show_list_progress: bool | None = None,
desc: str = "Downloading files",
custom_retry_protocol: Union[Callable[[WrappedFn], WrappedFn], None] = None,
custom_retry_protocol: Callable[[WrappedFn], WrappedFn] | None = None,
):
if show_list_progress is None:
show_list_progress = len(download_map) > 20
Expand All @@ -45,9 +45,7 @@ def download_with_progress(
retry_protocol = custom_retry_protocol # type: ignore

executor = concurrent.futures.ThreadPoolExecutor()
futures: dict[
concurrent.futures.Future, Tuple[str, Union[BufferedIOBase, str]]
] = dict()
futures: dict[concurrent.futures.Future, tuple[str, BufferedIOBase | str]] = dict()
bar = None

for src, dst, exp_size in download_map:
Expand Down Expand Up @@ -93,7 +91,7 @@ def download_with_progress(

def _download_with_progress(
url: str,
output: Union[BufferedIOBase, str],
output: BufferedIOBase | str,
expected_size: float,
show_progress: bool,
):
Expand Down Expand Up @@ -121,8 +119,8 @@ def _download_with_progress(
_logger.debug(f"Downloading from {url} to {output}...")

force_close = False
response: Union[Response, None] = None
buffer: Union[BufferedIOBase, None] = None
response: Response | None = None
buffer: BufferedIOBase | None = None
bar = None

try:
Expand Down
3 changes: 1 addition & 2 deletions clouddrift/adapters/yomaha.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import warnings
from datetime import datetime
from io import BytesIO
from typing import Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -71,7 +70,7 @@ def download(tmp_path: str):
buffer.close()


def to_xarray(tmp_path: Union[str, None] = None):
def to_xarray(tmp_path: str | None = None):
if tmp_path is None:
tmp_path = YOMAHA_TMP_PATH
os.makedirs(tmp_path, exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion clouddrift/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import os
from typing import Callable
from collections.abc import Callable

import xarray as xr

Expand Down
48 changes: 23 additions & 25 deletions clouddrift/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Functions for kinematic computations.
"""

from typing import Optional, Tuple, Union

import numpy as np
import pandas as pd
import xarray as xr
Expand All @@ -23,9 +21,9 @@


def kinetic_energy(
u: Union[float, list, np.ndarray, xr.DataArray, pd.Series],
v: Optional[Union[float, list, np.ndarray, xr.DataArray, pd.Series]] = None,
) -> Union[float, np.ndarray, xr.DataArray]:
u: float | list | np.ndarray | xr.DataArray | pd.Series,
v: float | list | np.ndarray | xr.DataArray | pd.Series | None = None,
) -> float | np.ndarray | xr.DataArray:
"""Compute kinetic energy from zonal and meridional velocities.
Parameters
Expand Down Expand Up @@ -65,10 +63,10 @@ def kinetic_energy(
def inertial_oscillation_from_position(
longitude: np.ndarray,
latitude: np.ndarray,
relative_bandwidth: Optional[float] = None,
wavelet_duration: Optional[float] = None,
time_step: Optional[float] = 3600.0,
relative_vorticity: Optional[Union[float, np.ndarray]] = 0.0,
relative_bandwidth: float | None = None,
wavelet_duration: float | None = None,
time_step: float | None = 3600.0,
relative_vorticity: float | np.ndarray | None = 0.0,
) -> np.ndarray:
"""Extract inertial oscillations from consecutive geographical positions.
Expand Down Expand Up @@ -262,11 +260,11 @@ def inertial_oscillation_from_position(


def residual_position_from_displacement(
longitude: Union[float, np.ndarray, xr.DataArray],
latitude: Union[float, np.ndarray, xr.DataArray],
x: Union[float, np.ndarray],
y: Union[float, np.ndarray],
) -> Union[Tuple[float], Tuple[np.ndarray]]:
longitude: float | np.ndarray | xr.DataArray,
latitude: float | np.ndarray | xr.DataArray,
x: float | np.ndarray,
y: float | np.ndarray,
) -> tuple[float] | tuple[np.ndarray]:
"""
Return residual longitudes and latitudes along a trajectory on the spherical Earth
after correcting for zonal and meridional displacements x and y in meters.
Expand Down Expand Up @@ -326,10 +324,10 @@ def position_from_velocity(
time: np.ndarray,
x_origin: float,
y_origin: float,
coord_system: Optional[str] = "spherical",
integration_scheme: Optional[str] = "forward",
time_axis: Optional[int] = -1,
) -> Tuple[np.ndarray, np.ndarray]:
coord_system: str | None = "spherical",
integration_scheme: str | None = "forward",
time_axis: int | None = -1,
) -> tuple[np.ndarray, np.ndarray]:
"""Compute positions from arrays of velocities and time and a pair of origin
coordinates.
Expand Down Expand Up @@ -530,10 +528,10 @@ def velocity_from_position(
x: np.ndarray,
y: np.ndarray,
time: np.ndarray,
coord_system: Optional[str] = "spherical",
difference_scheme: Optional[str] = "forward",
time_axis: Optional[int] = -1,
) -> Tuple[xr.DataArray, xr.DataArray]:
coord_system: str | None = "spherical",
difference_scheme: str | None = "forward",
time_axis: int | None = -1,
) -> tuple[xr.DataArray, xr.DataArray]:
"""Compute velocity from arrays of positions and time.
x and y can be provided as longitude and latitude in degrees if
Expand Down Expand Up @@ -779,9 +777,9 @@ def spin(
u: np.ndarray,
v: np.ndarray,
time: np.ndarray,
difference_scheme: Optional[str] = "forward",
time_axis: Optional[int] = -1,
) -> Union[float, np.ndarray]:
difference_scheme: str | None = "forward",
time_axis: int | None = -1,
) -> float | np.ndarray:
"""Compute spin continuously from velocities and times.
Spin is traditionally (Sawford, 1999; Veneziani et al., 2005) defined as
Expand Down
Loading

0 comments on commit c488f0d

Please sign in to comment.