Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylint fixes, remove deprecated functions #1881

Merged
merged 31 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5267a67
pylint fixes - first pass
Zeitsperre Aug 13, 2024
b466858
pylint adjustments - second pass
Zeitsperre Aug 13, 2024
f141072
address regression
Zeitsperre Aug 15, 2024
9397d1a
more pylint adjustments
Zeitsperre Aug 15, 2024
670bf3c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 15, 2024
f8fb82f
remove deprecated signatures and functions
Zeitsperre Aug 15, 2024
a4c91a6
fix op logic
Zeitsperre Aug 15, 2024
2729223
update pint usage
Zeitsperre Aug 15, 2024
7250962
add casting for returns, pin vulture
Zeitsperre Aug 15, 2024
cdb494b
add warning TODO message
Zeitsperre Aug 15, 2024
44aae9b
update CHANGELOG.rst
Zeitsperre Aug 16, 2024
9d1f34c
Merge branch 'main' into pylint-fixes
Zeitsperre Aug 16, 2024
412dd17
Merge branch 'main' into pylint-fixes
coxipi Aug 21, 2024
b26031a
fix loop
Zeitsperre Aug 22, 2024
259fb23
remove deprecated offset
coxipi Aug 22, 2024
a3917ff
Update xclim/sdba/utils.py
Zeitsperre Aug 22, 2024
88ac0a0
Merge branch 'main' into pylint-fixes
coxipi Aug 22, 2024
e4aed1d
add try/except workaround
Zeitsperre Aug 23, 2024
f25b56b
add skip on broken tests until #1889 is merged
Zeitsperre Aug 23, 2024
8e06ef2
update CHANGELOG.rst, adapt doctests to changes
Zeitsperre Aug 23, 2024
0523255
revert regression
Zeitsperre Aug 23, 2024
9e1b140
Merge branch 'main' into pylint-fixes
Zeitsperre Aug 28, 2024
291efd6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
4072cac
Merge branch 'main' into pylint-fixes
Zeitsperre Aug 29, 2024
a9cf4eb
Reduce some cyclic imports by migrating some common types and excepti…
Zeitsperre Aug 29, 2024
bf7ea75
remove walk_map, rename variables to reduce confusion, simplify chain…
Zeitsperre Aug 29, 2024
e44fab8
mark flaky test
Zeitsperre Aug 29, 2024
3133b77
Merge branch 'main' into pylint-fixes
Zeitsperre Sep 3, 2024
8719d84
update CHANGELOG.rst
Zeitsperre Sep 3, 2024
faec7d4
Merge branch 'main' into pylint-fixes
Zeitsperre Sep 3, 2024
1576c19
Merge branch 'main' into pylint-fixes
Zeitsperre Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .pylintrc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
# extension-pkg-allow-list =
extension-pkg-allow-list = ["cftime"]

# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
Expand All @@ -36,7 +36,7 @@ fail-under = 10
# from-stdin =

# Files or directories to be skipped. They should be base names, not paths.
ignore = ["CVS"]
ignore = ["CVS", "conftest.py"]

# Add files or directories matching the regular expressions patterns to the
# ignore-list. The regex matches against paths and can be in Posix or Windows
Expand All @@ -62,7 +62,7 @@ ignored-modules = ["xclim.indicators"]
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
# number of processors available to use, and will cap the count on Windows to
# avoid hangs.
jobs = 1
jobs = 4

# Control the amount of potential inferred values when inferring a single object.
# This can help the performance when dealing with large functions or complex,
Expand All @@ -78,7 +78,7 @@ persistent = true

# Minimum Python version to use for version dependent checks. Will default to the
# version used to run pylint.
py-version = "3.8"
py-version = "3.9"

# Discover python modules and packages in the file system subtree.
# recursive =
Expand Down Expand Up @@ -253,13 +253,13 @@ max-args = 15
max-attributes = 7

# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr = 5
max-bool-expr = 10

# Maximum number of branch for function / method body.
max-branches = 30

# Maximum number of locals for function / method body.
max-locals = 50
max-locals = 75

# Maximum number of parents for a class (see R0901).
max-parents = 7
Expand All @@ -268,7 +268,7 @@ max-parents = 7
max-public-methods = 20

# Maximum number of return / yield for function / method body.
max-returns = 13
max-returns = 15

# Maximum number of statements in function / method body.
max-statements = 100
Expand All @@ -295,10 +295,10 @@ indent-after-paren = 4
indent-string = " "

# Maximum number of characters on a single line.
max-line-length = 150
max-line-length = 200

# Maximum number of lines in a module.
max-module-lines = 1500
max-module-lines = 2000

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
Expand Down Expand Up @@ -373,6 +373,7 @@ disable = [
"invalid-name",
"invalid-unary-operand-type",
"locally-disabled",
"missing-function-docstring",
"missing-module-docstring",
"no-member",
"protected-access",
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Breaking changes
* As of ``cf_xarray>=0.9.3``, dimensionless quantities now use the ``"1"`` units attribute as specified by the CF conventions, previously an empty string was returned. (:pull:`1814`).
* The definitions of the ``frost_free_season_start`` and ``frost_free_season_end`` have been slightly changed to be coherent with the ``frost_free_season_length`` and `xclim`'s notion of ``season`` in general. Indicator and indices signature have been adapted to the new conventions. (:pull:`1845`).
* Season length indicators have been modified to return ``0`` for all cases where a proper season was not found, but the data is valid. Previously, a ``nan`` was given if neither a start nor an end were found, even if the data was valid, and a ``0`` was given if an end was found but without a valid start. (:pull:`1845`).
* The following previously-deprecated functions have now been removed from `xclim`: ``xclim.core.calendar.convert_calendar``, ``xclim.core.calendar.date_range``, ``xclim.core.calendar.date_range_like``, ``xclim.core.calendar.interp_calendar``, ``xclim.core.calendar.days_in_year``, ``xclim.core.calendar.datetime_to_decimal_year``. For guidance on how to migrate to alternatives, see the `version 0.50.0 Breaking changes <#v0-50-0-2024-06-17>`_. (:issue:`1010`, :pull:`1845`).

Bug fixes
^^^^^^^^^
Expand All @@ -37,6 +38,8 @@ Internal changes
* In order to adapt to changes in `pytest`, the doctest fixtures have been split from the main testing suite and doctests are now run using ``$ python -c 'from xclim.testing.utils import run_doctests; run_doctests()'``. (:pull:`1632`).
* `tox` has been reconfigured to run doctests in a separate environment (``tox -e doctests``). (:pull:`1632`).
* Added ``xclim.indices.generic.season`` to make season start, end, and length indices. Added a ``stat`` argument to ``xclim.indices.run_length.season`` to avoid returning a dataset. (:pull:`1845`).
* Many ``DeprecationWarning`` and ``FutureWarning`` messages emitted from `xarray` and `pint` have been addressed. (:issue:`1719`, :pull:`1881`).
* The codebase has been adjusted to address many `pylint`-related warnings and errors. In some cases, `casting` was used to redefine some `numpy` and `xarray` objects. (:issue:`1719`, :pull:`1881`).

CI changes
^^^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
xarray.CFTimeIndex.__module__ = "xarray"

import xclim # noqa
Zeitsperre marked this conversation as resolved.
Show resolved Hide resolved
from xclim import indicators as _indicators # noqa
from xclim.core.indicator import registry # noqa

# If extensions (or modules to document with autodoc) are in another
Expand All @@ -45,7 +46,7 @@
indicators = {}
# FIXME: Include cf module when its indicators documentation is improved.
for module in ("atmos", "generic", "land", "seaIce", "icclim", "anuclim"):
for key, ind in getattr(xclim.indicators, module).__dict__.items():
for key, ind in getattr(_indicators, module).__dict__.items():
if hasattr(ind, "_registry_id") and ind._registry_id in registry: # noqa
indicators[ind._registry_id] = { # noqa
"realm": ind.realm,
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dependencies:
- tokenize-rt >=5.2.0
- tox >=4.16.0
# - tox-conda # Will be added when a [email protected]+ compatible plugin is released.
- vulture # ==2.11 # The conda-forge version is out of date.
- vulture ==2.11
- xdoctest >=1.1.5
- yamllint >=1.35.1
- pip >=24.0
Expand Down
1 change: 1 addition & 0 deletions tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def test_to_agg_units(in_u, opfunc, op, exp, exp_u):
attrs={"units": in_u},
)

# FIXME: This is emitting warnings from deprecated DataArray.argmax() usage.
out = to_agg_units(getattr(da, opfunc)(), da, op)
np.testing.assert_allclose(out, exp)

Expand Down
2 changes: 1 addition & 1 deletion xclim/analog.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def pivot(x, y):

return np.max(np.abs(cx - cy))

return max(pivot(x, y), pivot(y, x))
return max(pivot(x, y), pivot(y, x)) # pylint: disable=arguments-out-of-order


@metric
Expand Down
8 changes: 4 additions & 4 deletions xclim/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

distributed = False
try:
from dask.distributed import Client, progress
from dask.distributed import Client, progress # pylint: disable=ungrouped-imports

distributed = True
except ImportError: # noqa: S110
Expand Down Expand Up @@ -361,7 +361,7 @@ def list_commands(self, ctx):
"show_version_info",
)

def get_command(self, ctx, name):
def get_command(self, ctx, cmd_name):
"""Return the requested command."""
command = {
"dataflags": dataflags,
Expand All @@ -370,9 +370,9 @@ def get_command(self, ctx, name):
"prefetch_testing_data": prefetch_testing_data,
"release_notes": release_notes,
"show_version_info": show_version_info,
}.get(name)
}.get(cmd_name)
if command is None:
command = _create_command(name)
command = _create_command(cmd_name)
return command


Expand Down
12 changes: 6 additions & 6 deletions xclim/core/bootstrapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ def bootstrap_func(compute_index_func: Callable, **kwargs) -> xarray.DataArray:
"`bootstrap` is unnecessary when no year overlap between reference "
"(percentiles period) and studied (index period) periods."
)
pdoy_args = dict(
window=per_da.attrs["window"],
alpha=per_da.attrs["alpha"],
beta=per_da.attrs["beta"],
per=per_da.percentiles.data[()],
)
pdoy_args = {
"window": per_da.attrs["window"],
"alpha": per_da.attrs["alpha"],
"beta": per_da.attrs["beta"],
"per": per_da.percentiles.data[()],
}
bfreq = _get_bootstrap_freq(kwargs["freq"])
# Group input array in years, with an offset matching freq
overlap_years_groups = overlap_da.resample(time=bfreq).groups
Expand Down
Loading
Loading