Skip to content

Commit

Permalink
Merge pull request #159 from GeoStat-Framework/pylint_fixes
Browse files Browse the repository at this point in the history
Pylint fixes
  • Loading branch information
MuellerSeb authored Apr 14, 2021
2 parents 773c538 + b50e3e3 commit 89c3794
Show file tree
Hide file tree
Showing 29 changed files with 265 additions and 164 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ on:
workflow_dispatch:

jobs:
format_check:
name: format check
source_check:
name: source check
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -31,12 +31,17 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black
pip install black pylint
pip install --editable .
- name: black check
run: |
python -m black --check .
- name: pylint check
run: |
python -m pylint gstools/
build_wheels:
name: wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
17 changes: 9 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ All notable changes to **GSTools** will be documented in this file.
#### Directional Variograms and Auto-binning ([#87](https://github.com/GeoStat-Framework/GSTools/issues/87), [#106](https://github.com/GeoStat-Framework/GSTools/issues/106), [#131](https://github.com/GeoStat-Framework/GSTools/issues/131))
- new routine name `vario_estimate` instead of `vario_estimate_unstructured` (old kept for legacy code) for simplicity
- new routine name `vario_estimate_axis` instead of `vario_estimate_structured` (old kept for legacy code) for simplicity
- **`vario_estimate`**
- **vario_estimate**
- added simple automatic binning routine to determine bins from given data (one third of box diameter as max bin distance, sturges rule for number of bins)
- allow to pass multiple fields for joint variogram estimation (e.g. for daily precipitation) on same mesh
- `no_data` option added to allow missing values
Expand All @@ -53,7 +53,7 @@ All notable changes to **GSTools** will be documented in this file.
- prepared for nD
- structured fields (pos tuple describes axes) can now be passed to estimate an isotropic or directional variogram
- distance calculation in cython routines in now independent of dimension
- **`vario_estimate_axis`**
- **vario_estimate_axis**
- estimation along array axis now possible in arbitrary dimensions
- `no_data` option added to allow missing values (sovles [#83](https://github.com/GeoStat-Framework/GSTools/issues/83))
- axis can be given by name (`"x"`, `"y"`, `"z"`) or axis number (`0`, `1`, `2`, `3`, ...)
Expand Down Expand Up @@ -141,6 +141,7 @@ All notable changes to **GSTools** will be documented in this file.
- isotropic rotation of SRF was not possible [#100](https://github.com/GeoStat-Framework/GSTools/issues/100)
- `CovModel.opt_arg` now sorted [#103](https://github.com/GeoStat-Framework/GSTools/issues/103)
- CovModel.fit: check if weights are given as a string (numpy comparison error) [#111](https://github.com/GeoStat-Framework/GSTools/issues/111)
- several pylint fixes ([#159](https://github.com/GeoStat-Framework/GSTools/pull/159))

## [1.2.1] - Volatile Violet - 2020-04-14

Expand Down Expand Up @@ -180,13 +181,13 @@ All notable changes to **GSTools** will be documented in this file.
## [1.1.1] - Reverberating Red - 2019-11-08

### Enhancements
- added a changelog. See: [commit](https://github.com/GeoStat-Framework/GSTools/commit/fbea88300d0862393e52f4b7c3d2b15c2039498b)
- added a changelog. See: [commit fbea883](https://github.com/GeoStat-Framework/GSTools/commit/fbea88300d0862393e52f4b7c3d2b15c2039498b)

### Changes
- deprecation warnings are now printed if Python versions 2.7 or 3.4 are used #40 #41

### Bugfixes
- define spectral_density instead of spectrum in covariance models since Cov-base derives spectrum. See: [commit](https://github.com/GeoStat-Framework/GSTools/commit/00f2747fd0503ff8806f2eebfba36acff813416b)
- define spectral_density instead of spectrum in covariance models since Cov-base derives spectrum. See: [commit 00f2747](https://github.com/GeoStat-Framework/GSTools/commit/00f2747fd0503ff8806f2eebfba36acff813416b)
- better boundaries for CovModel parameters. See: https://github.com/GeoStat-Framework/GSTools/issues/37


Expand All @@ -201,8 +202,8 @@ All notable changes to **GSTools** will be documented in this file.
- incompressible flow fields can now be generated #14
- new submodule providing several field transformations like: Zinn&Harvey, log-normal, bimodal, ... #13
- Python 3.4 and 3.7 wheel support #19
- field can now be generated directly on meshes from [meshio](https://github.com/nschloe/meshio) and [ogs5py](https://github.com/GeoStat-Framework/ogs5py), see: [commit](https://github.com/GeoStat-Framework/GSTools/commit/f4a3439400b81d8d9db81a5f7fbf6435f603cf05)
- the srf and kriging classes now store the last ``pos``, ``mesh_type`` and ``field`` values to keep them accessible, see: [commit](https://github.com/GeoStat-Framework/GSTools/commit/29f7f1b029866379ce881f44765f72534d757fae)
- field can now be generated directly on meshes from [meshio](https://github.com/nschloe/meshio) and [ogs5py](https://github.com/GeoStat-Framework/ogs5py), see: [commit f4a3439](https://github.com/GeoStat-Framework/GSTools/commit/f4a3439400b81d8d9db81a5f7fbf6435f603cf05)
- the srf and kriging classes now store the last ``pos``, ``mesh_type`` and ``field`` values to keep them accessible, see: [commit 29f7f1b](https://github.com/GeoStat-Framework/GSTools/commit/29f7f1b029866379ce881f44765f72534d757fae)
- tutorials on all important features of GSTools have been written for you guys #20
- a new interface to pyvista is provided to export fields to python vtk representation, which can be used for plotting, exploring and exporting fields #29

Expand All @@ -211,8 +212,8 @@ All notable changes to **GSTools** will be documented in this file.
- the rotation angles are now interpreted in positive direction (counter clock wise)
- the ``force_moments`` keyword was removed from the SRF call method, it is now in provided as a field transformation #13
- drop support of python implementations of the variogram estimators #18
- the ``variogram_normed`` method was removed from the ``CovModel`` class due to redundance [commit](https://github.com/GeoStat-Framework/GSTools/commit/25b164722ac6744ebc7e03f3c0bf1c30be1eba89)
- the position vector of 1D fields does not have to be provided in a list-like object with length 1 [commit](https://github.com/GeoStat-Framework/GSTools/commit/a6f5be8bfd2db1f002e7889ecb8e9a037ea08886)
- the ``variogram_normed`` method was removed from the ``CovModel`` class due to redundance [commit 25b1647](https://github.com/GeoStat-Framework/GSTools/commit/25b164722ac6744ebc7e03f3c0bf1c30be1eba89)
- the position vector of 1D fields does not have to be provided in a list-like object with length 1 [commit a6f5be8](https://github.com/GeoStat-Framework/GSTools/commit/a6f5be8bfd2db1f002e7889ecb8e9a037ea08886)

### Bugfixes
- several minor bugfixes
Expand Down
60 changes: 59 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,66 @@ with your idea or suggestion and we'd love to discuss about it.

- Fork the repo on [GitHub](https://github.com/GeoStat-Framework/GSTools) from the [develop branch](https://github.com/GeoStat-Framework/GSTools/tree/develop).
- Add yourself to AUTHORS.md (if you want to).
- We use the black code format, please use the script `black --line-length 79 gstools/` after you have written your code.
- We use the black code format, please use the script `black .` after you have written your code.
- Add some tests if possible.
- Add an example showing your new feature in one of the examples sub-folders if possible.
Follow this [Sphinx-Gallary guide](https://sphinx-gallery.github.io/stable/syntax.html#embed-rst-in-your-example-python-files)
- Push to your fork and submit a pull request.

### PyLint Settings

Your code will be checked by [Pylint](https://github.com/PyCQA/pylint/)
with `pylint gstools` in the CI.
We made some generous default settings in `pyproject.toml` for the linter:

- max-args = 20
- max-locals = 50
- max-branches = 30
- max-statements = 80
- max-attributes = 25
- max-public-methods = 75

Since some classes in GSTools are quite huge and some function signatures are
somewhat longish.

By default [R0801](https://vald-phoenix.github.io/pylint-errors/plerr/errors/similarities/R0801)
(duplicate-code) is disabled, since it produces a lot of false positive errors
for docstrings and `__init__.py` settings.

We also disabled some pylint checks for some files by setting
comments like these at the beginning:
```python
# pylint: disable=C0103
```

Here is a list of the occurring disabled errors:
- [C0103](https://vald-phoenix.github.io/pylint-errors/plerr/errors/basic/C0103)
(invalid-name) - `ax`, `r` etc. are marked as no valid names
- [C0302](https://vald-phoenix.github.io/pylint-errors/plerr/errors/format/C0302)
(too-many-lines) - namely the `CovModel` definition has more than 1000 lines
- [C0415](https://vald-phoenix.github.io/pylint-errors/plerr/errors/imports/C0415)
(import-outside-toplevel) - needed sometimes for deferred imports of optional
dependencies like `matplotlib`
- [R0201](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/R0201)
(no-self-use) - methods with no `self` calls in some base-classes
- [W0212](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/W0212)
(protected-access) - we didn't want to draw attention to `CovModel._prec`
- [W0221](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/W0221)
(arguments-differ) - the `__call__` methods of `SRF` and `Krige` differ from `Field`
- [W0222](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/W0222)
(signature-differ) - the `__call__` methods of `SRF` and `Krige` differ from `Field`
- [W0231](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/W0231)
(super-init-not-called) - some child classes have their specialized `__init__`
- [W0613](https://vald-phoenix.github.io/pylint-errors/plerr/errors/variables/W0613)
(unused-argument) - needed sometimes to match required call signatures
- [W0632](https://vald-phoenix.github.io/pylint-errors/plerr/errors/variables/W0632)
(unbalanced-tuple-unpacking) - false positive for some call returns
- [E1101](https://vald-phoenix.github.io/pylint-errors/plerr/errors/typecheck/E1101)
(no-member) - some times false positive
- [E1102](https://vald-phoenix.github.io/pylint-errors/plerr/errors/typecheck/E1102)
(not-callable) - this is a false-positive result form some called properties
- [E1130](https://vald-phoenix.github.io/pylint-errors/plerr/errors/typecheck/E1130)
(invalid-unary-operand-type) - false positive at some points

Although we disabled these errors at some points, we encourage you to prevent
disabling errors when it is possible.
15 changes: 6 additions & 9 deletions gstools/covmodel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
.. autosummary::
CovModel
"""
# pylint: disable=C0103, R0201, E1101

# pylint: disable=C0103, R0201, E1101, C0302, W0613
import copy
import numpy as np
from scipy.integrate import quad as integral
Expand Down Expand Up @@ -212,14 +211,12 @@ def __init_subclass__(cls):
cls.__doc__ = "User defined GSTools Covariance-Model."
cls.__doc__ += CovModel.__doc__[45:]
# overridden functions get standard doc if no new doc was created
ignore = ["__", "variogram", "covariance", "cor"]
for attr in cls.__dict__:
if any(
[attr.startswith(ign) for ign in ignore]
) or attr not in dir(CovModel):
ign = ["__", "variogram", "covariance", "cor"]
for att in cls.__dict__:
if any(att.startswith(i) for i in ign) or att not in dir(CovModel):
continue
attr_doc = getattr(CovModel, attr).__doc__
attr_cls = cls.__dict__[attr]
attr_doc = getattr(CovModel, att).__doc__
attr_cls = cls.__dict__[att]
if attr_cls.__doc__ is None:
attr_cls.__doc__ = attr_doc

Expand Down
5 changes: 2 additions & 3 deletions gstools/covmodel/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
.. autosummary::
fit_variogram
"""

# pylint: disable=C0103
# pylint: disable=C0103, W0632
import numpy as np
from scipy.optimize import curve_fit
from gstools.covmodel.tools import check_arg_in_bounds, default_arg_from_bounds
Expand Down Expand Up @@ -341,7 +340,7 @@ def _check_vario(model, x_data, y_data):
raise ValueError(
"CovModel.fit_variogram: lat-lon models don't support anisotropy."
)
elif model.latlon:
if model.latlon:
# convert to yadrenko model
x_data = 2 * np.sin(x_data / 2)
return x_data, y_data, is_dir_vario
Expand Down
5 changes: 2 additions & 3 deletions gstools/covmodel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
SuperSpherical
JBessel
"""
# pylint: disable=C0103, E1101, E1137, R0201

# pylint: disable=C0103, E1101, R0201
import warnings
import numpy as np
from scipy import special as sps
from gstools.covmodel.tools import AttributeWarning
from gstools.covmodel import CovModel
from gstools.covmodel.base import CovModel

__all__ = [
"Gaussian",
Expand Down
Loading

0 comments on commit 89c3794

Please sign in to comment.