Skip to content

Commit

Permalink
DEP: drop support for Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Nov 21, 2024
1 parent d353a11 commit 01be730
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 131 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ jobs:
os:
- ubuntu-latest
python-version:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
venv-loc: [bin]
include:
- os: ubuntu-20.04
python-version: '3.9'
python-version: '3.10'
venv-loc: bin
deps: minimal
install-args: --resolution=lowest-direct
Expand Down Expand Up @@ -97,7 +96,6 @@ jobs:
strategy:
matrix:
python-version:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
Expand Down
16 changes: 8 additions & 8 deletions nonos/_readers/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Optional, Union, final
from typing import final

import numpy as np

Expand All @@ -31,12 +31,12 @@
class VTKReader(ReaderMixin):
@staticmethod
def parse_output_number_and_filename(
file_or_number: Union[PathT, int],
file_or_number: PathT | int,
*,
directory: PathT,
prefix: str, # noqa: ARG004
) -> tuple[int, Path]:
if isinstance(file_or_number, (str, Path)):
if isinstance(file_or_number, str | Path):
file = Path(file_or_number)
if (m := re.search(r"\d+", file.name)) is None:
raise ValueError(
Expand Down Expand Up @@ -157,7 +157,7 @@ def read(file, /, **meta) -> BinData:
n2 = int(slist[2])
n3 = int(slist[3])

z: Union[np.ndarray, np.memmap]
z: np.ndarray | np.memmap

if V["geometry"] is Geometry.CARTESIAN:
s = fid.readline() # X_COORDINATES NX float
Expand Down Expand Up @@ -476,7 +476,7 @@ def read(file, /, **meta) -> BinData:
class _FargoReader(ReaderMixin, ABC):
@staticmethod
def parse_output_number_and_filename(
file_or_number: Union[PathT, int],
file_or_number: PathT | int,
*,
directory: PathT,
prefix: str, # noqa ARG004
Expand Down Expand Up @@ -536,7 +536,7 @@ def read(
output_number, directory = _FargoReader._get_output_number_and_dir_from(file)

default_fluid = "gas"
fluid_option: Optional[str] = meta.get("fluid", default_fluid)
fluid_option: str | None = meta.get("fluid", default_fluid)
if fluid_option is None:
fluid = default_fluid
else:
Expand Down Expand Up @@ -655,13 +655,13 @@ class NPYReader(ReaderMixin):

@staticmethod
def parse_output_number_and_filename(
file_or_number: Union[PathT, int],
file_or_number: PathT | int,
*,
directory: PathT,
prefix: str,
) -> tuple[int, Path]:
directory = Path(directory).resolve()
if isinstance(file_or_number, (str, Path)):
if isinstance(file_or_number, str | Path):
file = Path(file_or_number)
if (match := NPYReader._filename_re.fullmatch(file.name)) is None:
raise ValueError(f"Filename {file.name!r} is not recognized")
Expand Down
29 changes: 6 additions & 23 deletions nonos/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@
from dataclasses import dataclass
from enum import Enum, auto
from pathlib import Path
from typing import Any, Protocol, Union, final
from typing import Any, Protocol, TypeAlias, final

import numpy as np

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

if sys.version_info >= (3, 11):
from enum import StrEnum
from typing import assert_never
Expand All @@ -34,7 +29,7 @@
from nonos._backports import StrEnum


PathT: TypeAlias = Union[str, Path]
PathT: TypeAlias = str | Path
StrDict: TypeAlias = dict[str, Any]

FloatArray: TypeAlias = "np.ndarray[Any, np.dtype[np.float32 | np.float64]]"
Expand All @@ -53,10 +48,8 @@ class FrameType(Enum):


@final
@dataclass(frozen=True, eq=False)
@dataclass(frozen=True, eq=False, slots=True)
class BinData:
# TODO: use slots=True in @dataclass when Python 3.9 is dropped
__slots__ = ["data", "geometry", "x1", "x2", "x3"]
data: StrDict
geometry: Geometry
x1: FloatArray
Expand All @@ -71,10 +64,8 @@ def default_init(cls):


@final
@dataclass(frozen=True, eq=False)
@dataclass(frozen=True, eq=False, slots=True)
class OrbitalElements:
# TODO: use slots=True in @dataclass when Python 3.9 is dropped
__slots__ = ["i", "e", "a"]
i: FloatArray
e: FloatArray
a: FloatArray
Expand Down Expand Up @@ -148,16 +139,8 @@ def get_rotational_rate(self) -> FloatArray:


@final
@dataclass(frozen=True)
@dataclass(frozen=True, slots=True)
class IniData:
# TODO: use slots=True in @dataclass when Python 3.9 is dropped
__slots__ = [
"file",
"frame",
"rotational_rate",
"output_time_interval",
"meta",
]
file: Path
frame: FrameType
rotational_rate: float
Expand All @@ -168,7 +151,7 @@ class IniData:
class BinReader(Protocol):
@staticmethod
def parse_output_number_and_filename(
file_or_number: Union[PathT, int],
file_or_number: PathT | int,
*,
directory: PathT,
prefix: str,
Expand Down
14 changes: 7 additions & 7 deletions nonos/api/_angle_parsing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings
from collections.abc import Callable
from math import isclose
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING

if TYPE_CHECKING:
# note that these are documented as deprecated, but the replacement
Expand All @@ -10,15 +10,15 @@
from mypy_extensions import DefaultArg, DefaultNamedArg

find_phip_T = Callable[
[DefaultArg(Optional[int]), DefaultNamedArg(Optional[str], "planet_file")],
[DefaultArg(int | None), DefaultNamedArg(str | None, "planet_file")],
float,
]


def _parse_planet_file(
*,
planet_file: Optional[str] = None,
planet_number: Optional[int] = None,
planet_file: str | None = None,
planet_number: int | None = None,
) -> str:
if planet_number is not None and planet_file is not None:
raise TypeError(
Expand All @@ -33,9 +33,9 @@ def _parse_planet_file(

def _parse_rotation_angle(
*,
rotate_by: Optional[float],
rotate_with: Optional[str],
planet_number_argument: tuple[str, Optional[int]],
rotate_by: float | None,
rotate_with: str | None,
planet_number_argument: tuple[str, int | None],
find_phip: "find_phip_T",
stacklevel: int,
) -> float:
Expand Down
76 changes: 38 additions & 38 deletions nonos/api/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import cached_property
from pathlib import Path
from shutil import copyfile
from typing import TYPE_CHECKING, Any, Optional, Union, overload
from typing import TYPE_CHECKING, Any, overload

import numpy as np
from matplotlib.scale import SymmetricalLogTransform
Expand Down Expand Up @@ -295,7 +295,7 @@ def native_from_wanted(
self, _wanted_x1: str, _wanted_x2: None, /
) -> tuple[tuple[str], str]: ...

def native_from_wanted(self, _wanted_x1: str, _wanted_x2: Optional[str] = None, /):
def native_from_wanted(self, _wanted_x1: str, _wanted_x2: str | None = None, /):
if self.geometry == "cartesian":
conversion = {
"x": "x",
Expand Down Expand Up @@ -440,11 +440,11 @@ def __init__(
on: int,
operation: str,
*,
inifile: Optional[PathT] = None,
code: Union[str, Recipe, None] = None,
directory: Optional[PathT] = None,
rotate_by: Optional[float] = None,
rotate_with: Optional[str] = None,
inifile: PathT | None = None,
code: str | Recipe | None = None,
directory: PathT | None = None,
rotate_by: float | None = None,
rotate_with: str | None = None,
rotate_grid: int = -1, # deprecated
) -> None:
self.field = field
Expand Down Expand Up @@ -502,9 +502,9 @@ def shape(self) -> tuple[int, int, int]:
def map(
self,
*wanted,
rotate_by: Optional[float] = None,
rotate_with: Optional[str] = None,
planet_corotation: Optional[int] = None, # deprecated
rotate_by: float | None = None,
rotate_with: str | None = None,
planet_corotation: int | None = None, # deprecated
) -> Plotable:
rotate_by = _parse_rotation_angle(
rotate_by=rotate_by,
Expand Down Expand Up @@ -610,7 +610,7 @@ def rotate_axes(arr, shift: int):

def save(
self,
directory: Optional[PathT] = None,
directory: PathT | None = None,
header_only: bool = False,
) -> Path:
if directory is None:
Expand Down Expand Up @@ -676,8 +676,8 @@ def find_iphi(self, phi=0):
def _load_planet(
self,
*,
planet_number: Optional[int] = None,
planet_file: Optional[str] = None,
planet_number: int | None = None,
planet_file: str | None = None,
) -> PlanetData:
planet_file = _parse_planet_file(
planet_number=planet_number, planet_file=planet_file
Expand All @@ -692,19 +692,19 @@ def _get_ind_output_number(self, time) -> int:

def find_rp(
self,
planet_number: Optional[int] = None,
planet_number: int | None = None,
*,
planet_file: Optional[str] = None,
planet_file: str | None = None,
) -> float:
pd = self._load_planet(planet_number=planet_number, planet_file=planet_file)
ind_on = self._get_ind_output_number(pd.t)
return pd.d[ind_on] # type: ignore [attr-defined]

def find_rhill(
self,
planet_number: Optional[int] = None,
planet_number: int | None = None,
*,
planet_file: Optional[str] = None,
planet_file: str | None = None,
) -> float:
ini = self._loader.load_ini_file()
pd = self._load_planet(planet_number=planet_number, planet_file=planet_file)
Expand All @@ -714,9 +714,9 @@ def find_rhill(

def find_phip(
self,
planet_number: Optional[int] = None,
planet_number: int | None = None,
*,
planet_file: Optional[str] = None,
planet_file: str | None = None,
) -> float:
pd = self._load_planet(planet_number=planet_number, planet_file=planet_file)
ind_on = self._get_ind_output_number(pd.t)
Expand All @@ -727,7 +727,7 @@ def _parse_operation_name(
*,
prefix: str,
default_suffix: str,
operation_name: Optional[str],
operation_name: str | None,
) -> str:
if operation_name == "":
raise ValueError("operation_name cannot be empty")
Expand Down Expand Up @@ -1232,9 +1232,9 @@ def azimuthal_at_phi(self, phi=0.0, *, operation_name=None) -> "GasField":

def azimuthal_at_planet(
self,
planet_number: Optional[int] = None,
planet_number: int | None = None,
*,
planet_file: Optional[str] = None,
planet_file: str | None = None,
operation_name=None,
) -> "GasField":
planet_file = _parse_planet_file(
Expand Down Expand Up @@ -1308,9 +1308,9 @@ def azimuthal_average(self, *, operation_name=None) -> "GasField":

def remove_planet_hill_band(
self,
planet_number: Optional[int] = None,
planet_number: int | None = None,
*,
planet_file: Optional[str] = None,
planet_file: str | None = None,
operation_name=None,
) -> "GasField":
planet_file = _parse_planet_file(
Expand Down Expand Up @@ -1513,10 +1513,10 @@ def diff(self, on_2) -> "GasField":

def rotate(
self,
planet_corotation: Optional[int] = None,
planet_corotation: int | None = None,
*,
rotate_with: Optional[str] = None,
rotate_by: Optional[float] = None,
rotate_with: str | None = None,
rotate_by: float | None = None,
) -> "GasField":
rotate_by = _parse_rotation_angle(
rotate_by=rotate_by,
Expand Down Expand Up @@ -1602,17 +1602,17 @@ class GasDataSet:

def __init__(
self,
input_dataset: Union[int, PathT],
input_dataset: int | PathT,
/,
*,
inifile: Optional[PathT] = None,
code: Union[str, Recipe, None] = None,
geometry: Optional[str] = None,
directory: Optional[PathT] = None,
fluid: Optional[str] = None,
operation: Optional[str] = None,
inifile: PathT | None = None,
code: str | Recipe | None = None,
geometry: str | None = None,
directory: PathT | None = None,
fluid: str | None = None,
operation: str | None = None,
) -> None:
if isinstance(input_dataset, (str, Path)):
if isinstance(input_dataset, str | Path):
input_dataset = Path(input_dataset)
directory_from_input = input_dataset.parent
if directory is None:
Expand Down Expand Up @@ -1722,9 +1722,9 @@ def from_npy(
cls,
on: int,
*,
inifile: Optional[PathT] = None,
code: Union[str, Recipe, None] = None,
directory: Optional[PathT] = None,
inifile: PathT | None = None,
code: str | Recipe | None = None,
directory: PathT | None = None,
operation: str,
) -> "GasDataSet":
warnings.warn(
Expand Down
Loading

0 comments on commit 01be730

Please sign in to comment.