Skip to content

Commit

Permalink
Merge branch 'main' into prep0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
aulemahal authored May 7, 2024
2 parents 4eb68df + 7fb388b commit 863a4e9
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Internal changes
* An `encoding` argument was added to ``xs.config.load_config``. (:pull:`370`).
* Various small fixes to the code to address FutureWarnings. (:pull:`380`).
* ``xs.spatial.subset`` will try to guess CF coordinate if it can't find "latitude" or "longitude" in ``ds.cf``. (:pull:`384`).
* ``xs.extract_dataset`` and ``xs.DataCatalog.to_dataset`` will now default to opening datasets with option ``chunks={}``, which tries to respect chunking on disk. (:pull:`398`, :issue:`368`).

Bug fixes
^^^^^^^^^
Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ exclude = [
"build",
"docs"
]

[tool.ruff.format]
line-ending = "auto"

[tool.ruff.lint]
ignore = [
"D205",
"D400",
Expand All @@ -215,9 +220,6 @@ select = [
"W"
]

[tool.ruff.format]
line-ending = "auto"

[tool.ruff.lint.flake8-bandit]
check-typed-exception = true

Expand Down
15 changes: 0 additions & 15 deletions tests/test_ensembles.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,6 @@ def test_weights(self, weights, to_level):
decimal=2,
)

# FIXME: This function is deprecated, so this test should be removed eventually.
@pytest.mark.parametrize("p_vals", [True, False])
def test_change_significance(self, p_vals):
ens = self.make_ensemble(10)
with pytest.warns(
FutureWarning,
match="Function change_significance is deprecated as of xclim 0.47",
):
out = xs.ensemble_stats(
ens,
statistics={"change_significance": {"test": None, "p_vals": p_vals}},
)

assert len(out.data_vars) == 3 if p_vals else 2

@pytest.mark.parametrize("fractions", ["only", "both", "nested", "missing"])
def test_robustness_input(self, fractions):
ens = self.make_ensemble(10)
Expand Down
1 change: 0 additions & 1 deletion xscen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
__email__ = "[email protected]"
__version__ = "0.9.0"


def warning_on_one_line(
message: str, category: Warning, filename: str, lineno: int, file=None, line=None
):
Expand Down
4 changes: 4 additions & 0 deletions xscen/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from .config import CONFIG, args_as_str, recursive_update
from .utils import (
_xarray_defaults,
date_parser,
ensure_correct_time,
ensure_new_xrfreq,
Expand Down Expand Up @@ -529,6 +530,9 @@ def preprocess(ds):
raise ValueError(
f"Expected exactly one dataset, received {N} instead : {cat.keys()}"
)

kwargs = _xarray_defaults(**kwargs)

ds = cat.to_dask(**kwargs)
return ds

Expand Down
11 changes: 5 additions & 6 deletions xscen/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .config import parse_config
from .indicators import load_xclim_module, registry_from_module
from .spatial import subset
from .utils import CV
from .utils import CV, _xarray_defaults
from .utils import ensure_correct_time as _ensure_correct_time
from .utils import get_cat_attrs, natural_sort, standardize_periods, xrfreq_to_timedelta

Expand Down Expand Up @@ -161,17 +161,16 @@ def extract_dataset( # noqa: C901
}

# Default arguments to send xarray
xr_open_kwargs = xr_open_kwargs or {}
xr_combine_kwargs = xr_combine_kwargs or {}
xr_combine_kwargs.setdefault("data_vars", "minimal")
xr_kwargs = _xarray_defaults(
xr_open_kwargs=xr_open_kwargs or {}, xr_combine_kwargs=xr_combine_kwargs or {}
)

# Open the catalog
ds_dict = catalog.to_dataset_dict(
xarray_open_kwargs=xr_open_kwargs,
xarray_combine_by_coords_kwargs=xr_combine_kwargs,
preprocess=preprocess,
# Only print a progress bar when it is minimally useful
progressbar=(len(catalog.keys()) > 1),
**xr_kwargs,
)

out_dict = {}
Expand Down
2 changes: 1 addition & 1 deletion xscen/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _infer_freq_from_meta(ind):
ind.injected_parameters["freq"]
if "freq" in ind.injected_parameters
else (
ind.parameters["freq"]["default"]
ind.parameters["freq"].default
if "freq" in ind.parameters
else ind.src_freq
)
Expand Down
14 changes: 14 additions & 0 deletions xscen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,3 +1402,17 @@ def ensure_new_xrfreq(freq: str) -> str: # noqa: C901
freq = freq.replace("U", "us")

return freq


def _xarray_defaults(**kwargs):
"""Translate from xscen's extract names to intake-esm names and put better defaults."""
if "xr_open_kwargs" in kwargs:
kwargs["xarray_open_kwargs"] = kwargs.pop("xr_open_kwargs")
if "xr_combine_kwargs" in kwargs:
kwargs["xarray_combine_by_coords_kwargs"] = kwargs.pop("xr_combine_kwargs")

kwargs.setdefault("xarray_open_kwargs", {}).setdefault("chunks", {})
kwargs.setdefault("xarray_combine_by_coords_kwargs", {}).setdefault(
"data_vars", "minimal"
)
return kwargs

0 comments on commit 863a4e9

Please sign in to comment.