Skip to content

Commit

Permalink
Merge pull request #199 from Ouranosinc/abandon38
Browse files Browse the repository at this point in the history
Remove Python 3.8 support and fix other requirements
  • Loading branch information
RondeauG committed May 9, 2023
2 parents 6d0ddc8 + 294e6e9 commit d769f10
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/conda-build.yml
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
python-version: ["3.9"]
steps:
- uses: actions/checkout@v3
if: ${{ github.event.inputs.tag == '' }}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
python-version: "3.9"
- name: Install tox
run: |
pip install tox~=3.0
Expand All @@ -46,8 +46,6 @@ jobs:
tox-build: "py39"
- python-version: "3.10"
tox-build: "py310"
- python-version: "3.8"
tox-build: "doctests"
defaults:
run:
shell: bash -l {0}
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Expand Up @@ -6,7 +6,7 @@ repos:
rev: v3.4.0
hooks:
- id: pyupgrade
args: [--py38-plus]
args: [--py39-plus]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down Expand Up @@ -57,9 +57,9 @@ repos:
rev: 1.7.0
hooks:
- id: nbqa-pyupgrade
args: [ '--py38-plus' ]
args: [ '--py39-plus' ]
- id: nbqa-black
args: [ '--target-version=py38' ]
args: [ '--target-version=py39' ]
- id: nbqa-isort
args: [ "--settings-file=setup.cfg" ]
- repo: https://github.com/kynan/nbstripout
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Expand Up @@ -145,7 +145,7 @@ Before you submit a pull request, check that it meets these guidelines:
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
3. The pull request should not break the templates.
4. The pull request should work for Python 3.8, 3.9, and 3.10.
4. The pull request should work for Python 3.9 and 3.10.

Tips
----
Expand Down
24 changes: 24 additions & 0 deletions HISTORY.rst
Expand Up @@ -2,6 +2,30 @@
History
=======

v0.7.0 (unreleased)
-------------------
Contributors to this version: Gabriel Rondeau-Genesse (:user:`RondeauG`).

Announcements
^^^^^^^^^^^^^
* Dropped support for Python 3.8. (:pull:`199`).

New features and enhancements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* N/A

Breaking changes
^^^^^^^^^^^^^^^^
* N/A

Bug fixes
^^^^^^^^^
* N/A

Internal changes
^^^^^^^^^^^^^^^^
* Removed the pin on xarray's version. (:issue:`175`, :pull:`199`).

v0.6.0 (2023-05-04)
-------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Juliette Lavoie (:user:`juliettelavoie`), Pascal Bourgault (:user:`aulemahal`), Gabriel Rondeau-Genesse (:user:`RondeauG`).
Expand Down
4 changes: 2 additions & 2 deletions environment-dev.yml
Expand Up @@ -2,7 +2,7 @@ name: xscen-dev
channels:
- conda-forge
dependencies:
- python >=3.8
- python >=3.9
# Don't forget to sync the changes here with environment.yml!
# Some pins here are meant to accelerate conda and might not be related to real needs
# Main packages
Expand All @@ -25,7 +25,7 @@ dependencies:
- pyyaml
- rechunker
- shapely
- xarray <2023.3.0 # See https://github.com/Ouranosinc/xscen/pull/173
- xarray
- xclim >=0.37
- xesmf >=0.7
- zarr
Expand Down
4 changes: 2 additions & 2 deletions environment.yml
Expand Up @@ -2,7 +2,7 @@ name: xscen
channels:
- conda-forge
dependencies:
- python >=3.8
- python >=3.9
# Don't forget to sync the changes here with environment-dev.yml!
# Main packages
- cartopy
Expand All @@ -24,7 +24,7 @@ dependencies:
- pyyaml
- rechunker
- shapely
- xarray <2023.3.0 # See https://github.com/Ouranosinc/xscen/pull/173
- xarray
- xclim >=0.37
- xesmf >=0.7
- zarr
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Expand Up @@ -45,7 +45,7 @@
"pyyaml",
"rechunker",
"shapely",
"xarray<2023.3.0", # See https://github.com/Ouranosinc/xscen/pull/173
"xarray",
"xclim>=0.37",
"xesmf>=0.7", # This is not available on pypi.
"zarr",
Expand All @@ -54,15 +54,14 @@
setup(
author="Gabriel Rondeau-Genesse",
author_email="rondeau-genesse.gabriel@ouranos.ca",
python_requires=">=3.8",
python_requires=">=3.9",
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering :: Atmospheric Science",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = black, py{38,39,310}, docs, doctests
envlist = black, py{39,310}, docs, doctests
requires =
pip >= 20.0
tox < 4.0
Expand Down
8 changes: 6 additions & 2 deletions xscen/aggregate.py
Expand Up @@ -2,16 +2,18 @@
import datetime
import logging
import warnings
from collections.abc import Sequence
from copy import deepcopy
from pathlib import Path, PosixPath
from types import ModuleType
from typing import Sequence, Tuple, Union
from typing import Tuple, Union

import geopandas as gpd
import numpy as np
import pandas as pd
import pygeos
import xarray as xr
import xclim as xc
import xclim.core.calendar
import xesmf as xe
from shapely.geometry import Polygon
Expand Down Expand Up @@ -211,6 +213,8 @@ def compute_deltas(
"""
if isinstance(reference_horizon, str):
# Separate the reference from the other horizons
if xc.core.utils.uses_dask(ds["horizon"]):
ds["horizon"].load()
ref = ds.where(ds.horizon == reference_horizon, drop=True)
elif isinstance(reference_horizon, xr.Dataset):
ref = reference_horizon
Expand Down Expand Up @@ -640,7 +644,7 @@ def spatial_mean(
def produce_horizon(
ds: xr.Dataset,
indicators: Union[
str, PosixPath, Sequence[Indicator], Sequence[Tuple[str, Indicator]], ModuleType
str, PosixPath, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType
],
period: list = None,
to_level: str = "climatology{period0}-{period1}",
Expand Down
19 changes: 10 additions & 9 deletions xscen/catalog.py
Expand Up @@ -7,11 +7,12 @@
import re
import subprocess
import warnings
from collections.abc import Mapping, Sequence
from copy import deepcopy
from datetime import datetime
from glob import glob
from pathlib import Path, PosixPath
from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple, Union

import cftime
import dask
Expand Down Expand Up @@ -223,11 +224,11 @@ def from_csv(
# Create the intake catalog
return cls({"esmcat": esmdata, "df": df}, **intake_kwargs)

def __dir__(self) -> List[str]: # noqa: D105
def __dir__(self) -> list[str]: # noqa: D105
rv = ["iter_unique", "drop_duplicates", "check_valid"]
return super().__dir__() + rv

def _unique(self, columns) -> Dict:
def _unique(self, columns) -> dict:
def _find_unique(series):
values = series.dropna()
if series.name in self.esmcat.columns_with_iterables:
Expand Down Expand Up @@ -283,7 +284,7 @@ def search(self, **columns):
)
return cat

def drop_duplicates(self, columns: Optional[List[str]] = None): # noqa: D102
def drop_duplicates(self, columns: Optional[list[str]] = None): # noqa: D102
# In case variables are being added in an existing Zarr, append them
if columns is None:
columns = ["id", "path"]
Expand Down Expand Up @@ -364,8 +365,8 @@ def exists_in_cat(self, **columns):

def to_dataset(
self,
concat_on: Optional[Union[List[str], str]] = None,
create_ensemble_on: Optional[Union[List[str], str]] = None,
concat_on: Optional[Union[list[str], str]] = None,
create_ensemble_on: Optional[Union[list[str], str]] = None,
calendar: Optional[str] = "standard",
**kwargs,
) -> xr.Dataset:
Expand Down Expand Up @@ -1013,8 +1014,8 @@ def parse_directory(
read_from_file: Union[
bool,
Sequence[str],
Tuple[Sequence[str], Sequence[str]],
Sequence[Tuple[Sequence[str], Sequence[str]]],
tuple[Sequence[str], Sequence[str]],
Sequence[tuple[Sequence[str], Sequence[str]]],
] = False,
homogenous_info: dict = None,
cvs: Union[str, PosixPath, dict] = None,
Expand Down Expand Up @@ -1481,7 +1482,7 @@ def _parse_date(date, fmts):
return date


def _build_id(element: pd.Series, columns: List[str]):
def _build_id(element: pd.Series, columns: list[str]):
"""Build an ID from a catalog's row and a list of columns."""
return "_".join(map(str, filter(pd.notna, element[columns].values)))

Expand Down
2 changes: 1 addition & 1 deletion xscen/config.py
Expand Up @@ -117,7 +117,7 @@ def recursive_update(d, other):
return d


def args_as_str(*args: Tuple[Any, ...]) -> Tuple[str, ...]:
def args_as_str(*args: tuple[Any, ...]) -> tuple[str, ...]:
"""Return arguments as strings."""
new_args = []
for i, arg in enumerate(*args):
Expand Down
7 changes: 4 additions & 3 deletions xscen/diagnostics.py
@@ -1,9 +1,10 @@
# noqa: D100
import logging
import warnings
from collections.abc import Sequence
from pathlib import Path, PosixPath
from types import ModuleType
from typing import Optional, Sequence, Tuple, Union
from typing import Optional, Tuple, Union

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -78,7 +79,7 @@ def fix_unphysical_values(

def _invert_unphysical_temperatures(
tasmin: xr.DataArray, tasmax: xr.Dataset
) -> Tuple[xr.DataArray, xr.DataArray, xr.DataArray]:
) -> tuple[xr.DataArray, xr.DataArray, xr.DataArray]:
"""
Invert tasmin and tasmax points where tasmax < tasmin.
Expand Down Expand Up @@ -109,7 +110,7 @@ def _invert_unphysical_temperatures(
def properties_and_measures(
ds: xr.Dataset,
properties: Union[
str, PosixPath, Sequence[Indicator], Sequence[Tuple[str, Indicator]], ModuleType
str, PosixPath, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType
],
period: list = None,
unstack: bool = False,
Expand Down
4 changes: 2 additions & 2 deletions xscen/extract.py
Expand Up @@ -501,7 +501,7 @@ def resample(
@parse_config
def search_data_catalogs(
data_catalogs: Union[
Union[str, os.PathLike], List[Union[str, os.PathLike]], DataCatalog
Union[str, os.PathLike], list[Union[str, os.PathLike]], DataCatalog
],
variables_and_freqs: dict,
*,
Expand All @@ -510,7 +510,7 @@ def search_data_catalogs(
match_hist_and_fut: bool = False,
periods: list = None,
coverage_kwargs: dict = None,
id_columns: Optional[List[str]] = None,
id_columns: Optional[list[str]] = None,
allow_resampling: bool = False,
allow_conversion: bool = False,
conversion_yaml: str = None,
Expand Down
5 changes: 3 additions & 2 deletions xscen/indicators.py
@@ -1,9 +1,10 @@
# noqa: D100
import logging
from collections.abc import Sequence
from functools import partial
from pathlib import Path, PosixPath
from types import ModuleType
from typing import Sequence, Tuple, Union
from typing import Tuple, Union

import xarray as xr
import xclim as xc
Expand Down Expand Up @@ -60,7 +61,7 @@ def load_xclim_module(filename, reload=False) -> ModuleType:
def compute_indicators(
ds: xr.Dataset,
indicators: Union[
str, PosixPath, Sequence[Indicator], Sequence[Tuple[str, Indicator]], ModuleType
str, PosixPath, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType
],
*,
periods: list = None,
Expand Down
3 changes: 2 additions & 1 deletion xscen/io.py
Expand Up @@ -2,8 +2,9 @@
import logging
import os
import shutil as sh
from collections.abc import Sequence
from pathlib import Path
from typing import Optional, Sequence, Union
from typing import Optional, Union

import h5py
import netCDF4
Expand Down
2 changes: 1 addition & 1 deletion xscen/scripting.py
Expand Up @@ -39,7 +39,7 @@ def send_mail(
server: str = "127.0.0.1",
port: int = 25,
attachments: Optional[
List[Union[Tuple[str, Union[Figure, os.PathLike]], Figure, os.PathLike]]
list[Union[tuple[str, Union[Figure, os.PathLike]], Figure, os.PathLike]]
] = None,
) -> None:
"""Send email.
Expand Down
5 changes: 3 additions & 2 deletions xscen/utils.py
Expand Up @@ -3,11 +3,12 @@
import logging
import os
import re
from collections.abc import Sequence
from io import StringIO
from itertools import chain
from pathlib import Path
from types import ModuleType
from typing import Dict, Optional, Sequence, TextIO, Union
from typing import Dict, Optional, TextIO, Union

import flox.xarray
import numpy as np
Expand Down Expand Up @@ -746,7 +747,7 @@ def publish_release_notes(

def unstack_dates(
ds: xr.Dataset,
seasons: Dict[int, str] = None,
seasons: dict[int, str] = None,
new_dim: str = "season",
winter_starts_year: bool = False,
):
Expand Down

0 comments on commit d769f10

Please sign in to comment.