Skip to content

Commit

Permalink
Merge pull request #1044 from Ouranosinc/remove_ensembles_logging
Browse files Browse the repository at this point in the history
remove logging library from ensembles module
  • Loading branch information
Zeitsperre committed Mar 29, 2022
2 parents 6eb9005 + 694da2d commit 419f637
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ repos:
additional_dependencies: [ 'flake8-rst-docstrings' ]
args: [ '--config=setup.cfg' ]
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black
args: [ "--target-version", "py38" ]
additional_dependencies: ['click==8.0.4']
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Bug fixes
Internal changes
^^^^^^^^^^^^^^^^
* `xclim` now uses the ``check-json`` and ``pretty-format-json`` pre-commit checks to validate and format JSON files. (:pull:`1032`).
* The few `logging` artifacts in the ``xclim.ensembles`` module have been replaced with `warnings.warn` calls or removed. (:issue:`1039`, :pull:`1044`).

0.34.0 (25-02-2022)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
- scipy>=1.2
- xarray>=0.17
# Testing and development dependencies
- black
- black>=22.3
- bump2version
- coverage
- distributed>=2.0
Expand Down
3 changes: 1 addition & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# dev tools and testing
black
black>=22.3
bump2version
click==8.0.4
coverage
flake8
flake8-rst-docstrings
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ opts = -v
skip_install = True
extras =
deps =
click==8.0.4
flake8
flake8-rst-docstrings
black[jupyter]
Expand Down
3 changes: 1 addition & 2 deletions xclim/ensembles/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from xclim.core.calendar import convert_calendar, get_calendar
from xclim.core.formatting import update_history
from xclim.core.utils import calc_perc, logger
from xclim.core.utils import calc_perc


def create_ensemble(
Expand Down Expand Up @@ -302,7 +302,6 @@ def _ens_align_datasets(

ds_all = []
for i, n in enumerate(datasets):
logger.info(f"Accessing {n} of {len(datasets)}")
if mf_flag:
ds = xr.open_mfdataset(n, combine="by_coords", **xr_kwargs)
else:
Expand Down
11 changes: 4 additions & 7 deletions xclim/ensembles/_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
order to reduce the volume of computation needed while still covering a good portion of
the simulated climate variability.
"""
import logging
import warnings
from typing import Optional, Tuple, Union
from warnings import warn

import numpy as np
import scipy.stats
import xarray
from scipy.spatial.distance import cdist
from sklearn.cluster import KMeans

logger = logging.getLogger("xclim")

# Avoid having to include matplotlib in xclim requirements
try:
from matplotlib import pyplot as plt

logger.info("Matplotlib installed. Setting make_graph to True.")
warn("Matplotlib installed. Setting make_graph to True.")
MPL_INSTALLED = True

except ImportError:
logger.info("Matplotlib not found. No graph data will be produced.")
warn("Matplotlib not found. No graph data will be produced.")
plt = None
MPL_INSTALLED = False

Expand Down Expand Up @@ -370,7 +367,7 @@ def _get_nclust(method=None, n_sim=None, rsq=None, max_clusters=None):
else:
raise Exception(f"Unknown selection method : {list(method.keys())}")
if n_clusters > max_clusters:
warnings.warn(
warn(
f"{n_clusters} clusters has been found to be the optimal number of clusters, but limiting "
f"to {max_clusters} as required by user provided max_clusters",
UserWarning,
Expand Down

0 comments on commit 419f637

Please sign in to comment.