-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pylint fixes, remove deprecated functions (#1881)
### What kind of change does this PR introduce? * Adjust code base to address several `pylint`-related warnings. * Removes several deprecated calendar functions. * Pins the `vulture` dependency in `environment.yml` * Employed casting to deal with a few `numpy` * `xarray` typing issues. * Addressed a couple warnings related to `pint` usage. ### Does this PR introduce a breaking change? Yes, several calendar-related functions that were deprecated and slated for removal in `xclim` v0.50 and v0.51 have been removed. These will need to be listed in the `CHANGELOG.rst`. ### Other Information: I'm now a conda-forge maintainer for `vulture`, haha (https://github.com/conda-forge/vulture-feedstock)
- Loading branch information
Showing
64 changed files
with
755 additions
and
859 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
import warnings | ||
|
||
logger = logging.getLogger("xclim") | ||
|
||
__all__ = ["MissingVariableError", "ValidationError", "raise_warn_or_log"] | ||
|
||
|
||
class ValidationError(ValueError): | ||
"""Error raised when input data to an indicator fails the validation tests.""" | ||
|
||
@property | ||
def msg(self): # noqa | ||
return self.args[0] | ||
|
||
|
||
class MissingVariableError(ValueError): | ||
"""Error raised when a dataset is passed to an indicator but one of the needed variable is missing.""" | ||
|
||
|
||
def raise_warn_or_log( | ||
err: Exception, | ||
mode: str, | ||
msg: str | None = None, | ||
err_type: type = ValueError, | ||
stacklevel: int = 1, | ||
): | ||
"""Raise, warn or log an error according. | ||
Parameters | ||
---------- | ||
err : Exception | ||
An error. | ||
mode : {'ignore', 'log', 'warn', 'raise'} | ||
What to do with the error. | ||
msg : str, optional | ||
The string used when logging or warning. | ||
Defaults to the `msg` attr of the error (if present) or to "Failed with <err>". | ||
err_type : type | ||
The type of error/exception to raise. | ||
stacklevel : int | ||
Stacklevel when warning. Relative to the call of this function (1 is added). | ||
""" | ||
message = msg or getattr(err, "msg", f"Failed with {err!r}.") | ||
if mode == "ignore": | ||
pass | ||
elif mode == "log": | ||
logger.info(message) | ||
elif mode == "warn": | ||
warnings.warn(message, stacklevel=stacklevel + 1) | ||
else: # mode == "raise" | ||
raise err from err_type(message) |
Oops, something went wrong.