From c55ed28e72a54b0bb72e4697009efc2852c85319 Mon Sep 17 00:00:00 2001 From: Alif Be <11570927+alifbe@users.noreply.github.com> Date: Wed, 31 Jan 2024 22:42:14 +0100 Subject: [PATCH] Switch to ruff (#430) - Use ruff for code linting and formatting close #429 - Update contributing documentation - Remove sphinx pin --- .codacy.yml | 3 - .flake8 | 5 - .github/workflows/pyscal.yml | 17 +- .pylintrc | 23 -- .travis.yml | 30 -- CONTRIBUTING.rst | 83 +++-- README.md | 2 +- docs/conf.py | 5 +- docs/make_plots.py | 144 ++++----- pyproject.toml | 34 +- pyscal/__init__.py | 9 +- pyscal/factory.py | 39 +-- pyscal/gasoil.py | 44 +-- pyscal/gaswater.py | 5 +- pyscal/plotting.py | 28 +- pyscal/pyscalcli.py | 5 +- pyscal/pyscallist.py | 7 +- pyscal/scalrecommendation.py | 19 +- pyscal/utils/capillarypressure.py | 9 +- pyscal/utils/monotonicity.py | 19 +- pyscal/utils/relperm.py | 2 +- pyscal/utils/testing.py | 15 +- pyscal/wateroil.py | 56 ++-- pyscal/wateroilgas.py | 2 +- tests/test_factory.py | 436 +++++++++++++++----------- tests/test_fromtable.py | 2 +- tests/test_gasoil.py | 8 +- tests/test_gaswater.py | 1 - tests/test_interactive_plots.py | 12 +- tests/test_pyscalcli.py | 7 +- tests/test_pyscallist.py | 6 +- tests/test_slgof.py | 2 +- tests/test_utils_capillarypressure.py | 8 - tests/test_utils_interpolation.py | 5 - tests/test_wateroil.py | 3 +- tests/test_wateroil_saturation.py | 6 +- tests/test_wateroilgas.py | 1 - 37 files changed, 531 insertions(+), 571 deletions(-) delete mode 100644 .codacy.yml delete mode 100644 .flake8 delete mode 100644 .pylintrc delete mode 100644 .travis.yml diff --git a/.codacy.yml b/.codacy.yml deleted file mode 100644 index 5c84a461..00000000 --- a/.codacy.yml +++ /dev/null @@ -1,3 +0,0 @@ -exclude_paths: - # These files stem from a different project. - - docs/conf.py diff --git a/.flake8 b/.flake8 deleted file mode 100644 index a56b478e..00000000 --- a/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -exclude = docs, pyscal/__init__.py, pyscal/version.py -max-line-length = 88 -ignore = E741, W503, E203 -# E203: "whitespace before ':'", added due to conflict with black diff --git a/.github/workflows/pyscal.yml b/.github/workflows/pyscal.yml index 27cfe606..a92a620c 100644 --- a/.github/workflows/pyscal.yml +++ b/.github/workflows/pyscal.yml @@ -58,25 +58,20 @@ jobs: if: ${{ always() }} run: pip freeze - - name: Lint with black + - name: Ruff check if: ${{ always() }} run: | - black --check --force-exclude="pyscal/version.py" pyscal tests docs - - - name: Lint with flake8 - if: ${{ always() }} - run: | - flake8 pyscal tests - - - name: Lint with isort + ruff check . + + - name: Ruff format if: ${{ always() }} run: | - isort --check-only --profile black pyscal tests + ruff format . --check - name: Check typing with mypy if: ${{ always() }} run: | - mypy pyscal + mypy ./pyscal - name: Run tests if: ${{ always() }} diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index 55299713..00000000 --- a/.pylintrc +++ /dev/null @@ -1,23 +0,0 @@ -[GENERAL] -disable=R0205, F0010, C0330, E1136, E0401 -output-format=colorized - -[MASTER] -ignore=setup.py,version.py - -# We allow a lot of "bad" variable names, because it is important to keep the link to the original formulas -[BASIC] -good-names=df,logger,h,l,e,t,SGFN,SWOF,SGOF,SLGOF,SOF3,SWFN,WOTABLE,GOTABLE,nw,ng,Ls,Es,Ts,Lf,Ef,Tf,Pcmax,Pcmin,Pct,add_LET_pc_pd,Lp,Ep,Tp,Lt,Et,Tt,add_LET_pc_pd,Lp,Ep,Tp,Lt,Et,Tt,cw,co,aw,ao,a,b,g,add_LET_water,add_LET_oil,add_LET_gas,add_LET_pc_imb,add_simple_J,add_normalized_J,add_simple_J_petro - -[FORMAT] -max-line-length=88 -max-module-lines=3000 - -[DESIGN] -max-args=10 - -[SIMILARITIES] -min-similarity-lines=6 -ignore-comments=yes -ignore-docstrings=yes -ignore-imports=yes diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 974fd846..00000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -language: python - -python: -- '2.7' -- '3.6' -- '3.7' -- '3.8' - -install: -- pip install -r requirements.txt -- pip install -r requirements_dev.txt -- pip install . - -script: -- python setup.py test -- sphinx-apidoc -f -H "API for pyscal" -o docs pyscal -- python setup.py build_sphinx -- touch build/sphinx/html/.nojekyll - -deploy: -- provider: pages - skip_cleanup: true - local_dir: "./build/sphinx/html" - github_token: - secure: "tmv4rjGV4v4iqPEziUcHfTUg5mObF4i8jX4rTyfeom2NfOObT+ytHwt4yW3xPK8O8FgXoDTNGtCj/cc7Bf/oTS4FNKGuhceTr7/bkaQYdLDlVjlWXsx3A9QeHF+29nBfBOEfirj6v9UL/eDxTZCBThoxAZ89LDO5WWeoa7E4A6C4I2ctu+UaGiqCk0j+MpIjy0IDUyLl36KZeDowIgm05Wo//IGh1AaRY9SuzKChPE/HsOEcMNyh2kP8iKITmCKFaMnPLhsm/i3D6lEN9SZN+O4APddSTGs8moyyYBLyTvmUcEI8R1igLL/0G/yjlBfu4FmVEvznV1+GQOt9MHU0WL4N1p2VKLff20TVhhto8CH3zHjLz+vDpjq444Gg2/HB/OynNtbyzfUONap6z61kMvd/uu2EfBh1OlewQA+PPAm1F5Rt7U52D1umbsZ9IGaLUp5o2eLjmdor770FE+MpFX02cGGQYM1Nx9IckJNLVoZtlX2G7wzmYsoflzkNvbdu9x+jCI71WUBBszhBj+XePxtF31DRoV8Jg+wxvZX93MYgV76c4su02cd/+02UiDWAAfVvl5e7N77vikRicqIquN9GdOSi/kwJDeJlAfpAFaY1j/LU2tcNLmVcaEFK9/XNliO+0e8wlB7d/KsNF5AFon2ukg92Ebs3KerHT2voGng=" - keep_history: true - on: - branch: master - python: "3.6" - repo: equinor/pyscal diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 9e1b6cf3..e6e11731 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -5,42 +5,79 @@ Contributing to pyscal * Submit bugs on github * Pull requests are welcome! -Code style ----------- -* Use the black formatter to format your code +Create pull request +------------------- - * ``pip install black`` - * ``black `` -- must be done prior to any pull request. +1. Fork the pyscal repository from the Equinor repository to your GitHub + user account. -* Use flake8 code checker +2. Clone your fork locally: + + .. code-block:: bash + + git clone git@github.com:your_name_here/pyscal + cd pyscal + git remote add upstream git@github.com:equinor/pyscal + git remote -v + # origin git@github.com:your_name_here/pyscal (fetch) + # origin git@github.com:your_name_here/pyscal (push) + # upstream git@github.com:equinor/pyscal (fetch) + # upstream git@github.com:equinor/pyscal (push) - * ``pip install flake8`` - * ``flake8 src tests`` must pass before any pull request is accepted - * Exceptions are listed in ``setup.cfg`` +4. Install your forked copy into a local venv: -* Use pylint to improve coding + .. code-block:: bash + + python -m venv ~/venv/pyscal + source ~/venv/pyscal/bin/activate + pip install -U pip + pip install -e ".[tests,docs]" + +5. Run the tests to ensure everything works: - * ``pip install pylint`` - * Then run ``pylint pyscal`` - * Deviations from default (strict) pylint are stored in ``.pylintrc`` at root level, - or as comments in the file e.g. ``# pylint: disable=broad-except``. - * Only use deviations when e.g. black and pylint are in conflict, or if conformity with - pylint would clearly make the code worse or not work at all. Do not use it to - increase pylint score. + .. code-block:: bash + + pytest -n auto + +6. Create a branch for local development: + + .. code-block:: bash + + git checkout -b name-of-your-bugfix-or-feature + +Now you can make your changes locally. + +7. When you're done making changes, check that your changes pass ruff, mypy and the + tests: + + .. code-block:: bash + + ruff check . + ruff format . + mypy ./pyscal + pytest -n auto + +8. Commit your changes and push your branch to GitHub: + + .. code-block:: bash + + git add file1.py file2.py + git commit -m "Add some feature" + git push origin name-of-your-bugfix-or-feature + +9. Submit a pull request through GitHub. -* All code must be throroughly tested with ``pytest``. Building documentation ---------------------- -Install the development requirements:: - - pip install .[tests] +To build the documentation for pyscal run the following command: -Then, to build the documentation for pyscal run the following command:: + .. code-block:: bash - python setup.py build_sphinx + python docs/make_plots.py + sphinx-build -b html docs ./build/sphinx/html And now you can find the start page of the documentation in the build folder: ``build/sphinx/html/index.html``. diff --git a/README.md b/README.md index ac411531..2388e36b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Build Status](https://github.com/equinor/pyscal/actions/workflows/pyscal.yml/badge.svg)](https://github.com/equinor/pyscal/actions?query=workflow%3Apyscal) [![codecov](https://codecov.io/gh/equinor/pyscal/branch/master/graph/badge.svg)](https://codecov.io/gh/equinor/pyscal) [![Python 3.8-3.11](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10|%203.11-blue.svg)](https://www.python.org) -[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://black.readthedocs.io/) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![PyPI version](https://badge.fury.io/py/pyscal.svg)](https://badge.fury.io/py/pyscal) [![Downloads](https://pepy.tech/badge/pyscal)](https://pepy.tech/project/pyscal) [![License: GPL v3](https://img.shields.io/badge/License-LGPLv3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) diff --git a/docs/conf.py b/docs/conf.py index dca3c63e..b1554555 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,12 +14,11 @@ # import os # import sys # sys.path.insert(0, os.path.abspath('.')) -import pkg_resources import datetime -# -- Project information ----------------------------------------------------- +import pkg_resources -import pyscal +# -- Project information ----------------------------------------------------- project = "pyscal" author = "Håvard Berland" diff --git a/docs/make_plots.py b/docs/make_plots.py index 61652f0f..842536a1 100644 --- a/docs/make_plots.py +++ b/docs/make_plots.py @@ -66,19 +66,19 @@ def make_gasoil_endpoints(show=True, krgendanchor="sorg"): axes.annotate( "KROMAX", xy=(0, kromax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(0.1, kromax + 0.07), ) axes.annotate( "KROEND", xy=(sgro, kroend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(sgro + 0.07, kroend + 0.05), ) axes.annotate( "KRGEND", xy=(1 - sorg - swl, krgend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - sorg - swl + 0.01, krgmax - 0.2), ) # Overwrite with same text at identical spots for @@ -86,36 +86,36 @@ def make_gasoil_endpoints(show=True, krgendanchor="sorg"): axes.annotate( "KRGEND", xy=(1 - swl, krgend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - sorg - swl + 0.01, krgmax - 0.2), ) axes.annotate( "KRGMAX", xy=(1 - swl, krgmax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - swl - 0.2, krgmax + 0.1), ) axes.text(0.0, 0.07, "SGCR") axes.annotate( - "", xy=(-0.01, 0.04), xytext=(sgcr, 0.04), arrowprops=dict(arrowstyle="<->") + "", xy=(-0.01, 0.04), xytext=(sgcr, 0.04), arrowprops={"arrowstyle": "<->"} ) axes.text(0.0, 0.73, "SGRO") axes.annotate( "", xy=(-0.01, kroend - 0.02), xytext=(sgro, kroend - 0.02), - arrowprops=dict(arrowstyle="<->"), + arrowprops={"arrowstyle": "<->"}, ) plt.xlabel("SG", labelpad=-10) axes.annotate( "", xy=(1 - sorg - swl, 0.02), xytext=(1 - swl, 0.02), - arrowprops=dict(arrowstyle="<->"), + arrowprops={"arrowstyle": "<->"}, ) axes.text(1 - sorg - swl + 0.04, 0.04, "SORG") axes.annotate( - "", xy=(1 - swl, 0.02), xytext=(1, 0.02), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - swl, 0.02), xytext=(1, 0.02), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - swl + 0.04, 0.04, "SWL") axes.legend(loc="upper center") @@ -149,42 +149,42 @@ def make_wateroil_endpoints(show=True): axes.annotate( "KROEND", xy=(swl, kroend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.1, kroend - 0.3), ) axes.annotate( "KRWEND", xy=(1 - sorw, krwend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - sorw - 0.09, krwmax - 0.2), ) axes.annotate( "KRWMAX", xy=(1, krwmax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.1, krwmax - 0.3), ) axes.annotate( "SWIRR", xy=(swirr, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swirr - 0.12, 0 + 0.1), ) axes.annotate( "SWL", xy=(swl, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.05, 0 + 0.14), ) axes.annotate( "SWCR", xy=(swcr, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swcr - 0.06, 0 + 0.21), ) plt.xlabel("SW", labelpad=-10) axes.annotate( - "", xy=(1 - sorw, 0.02), xytext=(1, 0.02), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sorw, 0.02), xytext=(1, 0.02), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - sorw + 0.04, 0.04, "SORW") if show: @@ -218,49 +218,49 @@ def make_gaswater_endpoints(show=True): axes.annotate( "KRGEND", xy=(swl, krgend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.1, krgend - 0.3), ) axes.annotate( "KRWEND", xy=(1 - sgrw, krwend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - sgrw - 0.23, krwmax - 0.2), ) axes.annotate( "KRWMAX", xy=(1, krwmax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.1, krwmax - 0.3), ) axes.annotate( "SWIRR", xy=(swirr, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swirr - 0.12, 0 + 0.1), ) axes.annotate( "SWL", xy=(swl, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.05, 0 + 0.14), ) axes.annotate( "SWCR", xy=(swcr, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swcr - 0.06, 0 + 0.21), ) plt.xlabel("SW", labelpad=-10) axes.text(1 - sgrw + 0.04, 0.04, "SGRW") axes.annotate( - "", xy=(1 - sgrw, 0.02), xytext=(1, 0.02), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgrw, 0.02), xytext=(1, 0.02), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - sgcr + 0.04, 0.14, "SGCR") axes.annotate( - "", xy=(1 - sgcr, 0.12), xytext=(1, 0.12), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgcr, 0.12), xytext=(1, 0.12), arrowprops={"arrowstyle": "<->"} ) if show: @@ -293,37 +293,37 @@ def make_wateroil_idc2(show=True): axes.annotate( "KROEND", xy=(swl, kroend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl + 0.1, kroend + 0.1), ) axes.annotate( "KRWEND", xy=(1 - sorw, krwend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.15, krwend - 0.02), ) axes.annotate( "KRWMAX", xy=(1, krwmax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.3, krwmax - 0.02), ) axes.annotate( "SWIRR", xy=(swirr, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swirr - 0.12, 0 + 0.1), ) axes.annotate( "SWL≈SWCR", xy=(swl, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.055, 0 + 0.14), ) plt.xlabel("SW", labelpad=-10) axes.legend(loc="upper center") axes.annotate( - "", xy=(1 - sorw, 0.02), xytext=(1, 0.02), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sorw, 0.02), xytext=(1, 0.02), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - sorw + 0.04, 0.04, "SORW") @@ -377,25 +377,25 @@ def make_gasoil_cdi2(show=True): axes.annotate( "KROEND", xy=(0, kroend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(0.1, kroend + 0.02), ) axes.annotate( "KRGEND", xy=(1 - sorg - swl, krgend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.2, krgend - 0.02), ) axes.annotate( "KRGMAX", xy=(1 - swl, krgmax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.35, krgmax - 0.04), ) axes.annotate( "SGCR", xy=(sgcr, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(sgcr - 0.05, 0 + 0.14), ) plt.xlabel("SG", labelpad=-10) @@ -403,11 +403,11 @@ def make_gasoil_cdi2(show=True): "", xy=(1 - sorg - swl, 0.02), xytext=(1 - swl, 0.02), - arrowprops=dict(arrowstyle="<->"), + arrowprops={"arrowstyle": "<->"}, ) axes.text(1 - sorg - swl + 0.04, 0.04, "SORG") axes.annotate( - "", xy=(1 - swl, 0.02), xytext=(1, 0.02), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - swl, 0.02), xytext=(1, 0.02), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - swl + 0.04, 0.04, "SWL") axes.legend(loc="upper center") @@ -463,25 +463,25 @@ def make_gasoil_cid2(show=True): axes.annotate( "KROEND", xy=(sgro, kroend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(sgro + 0.1, kroend - 0.05), ) axes.annotate( "KROMAX", xy=(0, kromax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(0.1, kromax + 0.05), ) axes.annotate( "KRGEND", xy=(1 - swl, krgend - 0.01), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.35, krgend - 0.04), ) axes.annotate( "SGCR=SGRO", xy=(sgcr, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(sgcr - 0.1, 0 + 0.14), ) plt.xlabel("SG", labelpad=-10) @@ -489,11 +489,11 @@ def make_gasoil_cid2(show=True): "", xy=(1 - sorg - swl, 0.08), xytext=(1 - swl, 0.08), - arrowprops=dict(arrowstyle="<->"), + arrowprops={"arrowstyle": "<->"}, ) axes.text(1 - sorg - swl + 0.02, 0.1, "SORG") axes.annotate( - "", xy=(1 - swl, 0.02), xytext=(1, 0.02), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - swl, 0.02), xytext=(1, 0.02), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - swl + 0.04, 0.04, "SWL") axes.legend(loc="upper center") @@ -547,43 +547,43 @@ def make_gaswater_icd2(show=True): axes.annotate( "KRGEND", xy=(swl, krgend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl + 0.1, krgend - 0.1), ) axes.annotate( "KRWEND", xy=(1 - sgrw, krwend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - sgrw - 0.23, krwmax - 0.1), ) axes.annotate( "KRWMAX", xy=(1 - 0.01, krwmax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.23, krwmax), ) axes.annotate( "SWL", xy=(swl, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.07, 0 + 0.12), ) axes.annotate( "SWCR", xy=(swcr, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swcr - 0.06, 0 + 0.21), ) plt.xlabel("SW", labelpad=-10) axes.text(1 - sgrw + 0.04, 0.04, "SGRW") axes.annotate( - "", xy=(1 - sgrw, 0.02), xytext=(1, 0.02), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgrw, 0.02), xytext=(1, 0.02), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - sgcr + 0.04, 0.14, "SGCR") axes.annotate( - "", xy=(1 - sgcr, 0.12), xytext=(1, 0.12), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgcr, 0.12), xytext=(1, 0.12), arrowprops={"arrowstyle": "<->"} ) # Initial state and saturation direction: @@ -637,31 +637,31 @@ def make_gaswater_dci1(show=True): axes.annotate( "KRGEND", xy=(swl, krgend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl + 0.1, krgend - 0.1), ) axes.annotate( "KRWEND", xy=(1 - sgrw, krwend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - sgrw - 0.23, krwend - 0.1), ) axes.annotate( "SWL=SWCR", xy=(swl, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.08, 0 + 0.1), ) plt.xlabel("SW", labelpad=-10) # axes.text(1 - sgrw + 0.04, 0.04, "SGRW") axes.annotate( - "", xy=(1 - sgrw, 0.02), xytext=(1, 0.02), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgrw, 0.02), xytext=(1, 0.02), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - sgcr + 0.04, 0.14, "SGCR") axes.annotate( - "", xy=(1 - sgcr, 0.12), xytext=(1, 0.12), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgcr, 0.12), xytext=(1, 0.12), arrowprops={"arrowstyle": "<->"} ) # Initial state and saturation direction: @@ -717,32 +717,32 @@ def make_gaswater_co2_icd2(show=True): axes.annotate( "KRGEND", xy=(swl, krgend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl + 0.1, krgend - 0.1), ) axes.annotate( "KRWEND", xy=(1 - sgrw, krwend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - sgrw - 0.23, krwend + 0.1), ) axes.annotate( "KRWMAX", xy=(1, krwmax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.23, krwmax - 0.1), ) axes.annotate( "SWL=SWCR", xy=(swl, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.1, 0 + 0.1), ) plt.xlabel("SW", labelpad=-10) axes.text(1 - sgrw + 0.04, 0.04, "SGRW=SGCR") axes.annotate( - "", xy=(1 - sgrw, 0.02), xytext=(1, 0.02), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgrw, 0.02), xytext=(1, 0.02), arrowprops={"arrowstyle": "<->"} ) # Initial state and saturation direction: @@ -797,43 +797,43 @@ def make_wateroil_paleooil_idc1(show=True): axes.annotate( "KROEND", xy=(swl, kroend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl + 0.07, kroend), ) axes.annotate( "KRWEND", xy=(1 - sorw, krwend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - sorw - 0.15, krwend + 0.05), ) axes.annotate( "KRWMAX", xy=(1, krwmax), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - 0.25, krwmax - 0.05), ) axes.annotate( "SWL", xy=(swl, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.05, 0 + 0.14), ) axes.annotate( "SWCR", xy=(swcr, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swcr - 0.06, 0 + 0.21), ) plt.xlabel("SW", labelpad=-10) axes.annotate( - "", xy=(1 - sorw, krwend), xytext=(1, krwend), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sorw, krwend), xytext=(1, krwend), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - sorw + 0.03, krwend - 0.05, "SORW") axes.annotate( "", xy=(1 - socr, 0.12), xytext=(1, 0.12), - arrowprops=dict(arrowstyle="<->"), + arrowprops={"arrowstyle": "<->"}, ) axes.text(1 - socr + 0.05, 0.14, "SOCR") axes.legend(loc="upper center") @@ -889,19 +889,19 @@ def make_gaswater_paleogas_dci3(show=True): axes.annotate( "KRGEND", xy=(swl, krgend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.1, krgend - 0.3), ) axes.annotate( "KRWEND", xy=(1 - sgrw, krwend), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(1 - sgrw - 0.23, krwend - 0.1), ) axes.annotate( "SWL=SWCR", xy=(swl, 0), - arrowprops=dict(arrowstyle="->"), + arrowprops={"arrowstyle": "->"}, xytext=(swl - 0.1, 0 + 0.14), ) plt.xlabel("SW", labelpad=-10) @@ -909,17 +909,17 @@ def make_gaswater_paleogas_dci3(show=True): axes.text(1 - sgrw + 0.01, krwend - 0.05, "SGRW") axes.annotate( - "", xy=(1 - sgrw, krwend), xytext=(1, krwend), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgrw, krwend), xytext=(1, krwend), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - sgcr + 0.04, 0.09, "SGCR") axes.annotate( - "", xy=(1 - sgcr, 0.07), xytext=(1, 0.07), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgcr, 0.07), xytext=(1, 0.07), arrowprops={"arrowstyle": "<->"} ) axes.text(1 - sgl + 0.02, 0.02, "SGL") axes.annotate( - "", xy=(1 - sgl, 0.00), xytext=(1, 0.00), arrowprops=dict(arrowstyle="<->") + "", xy=(1 - sgl, 0.00), xytext=(1, 0.00), arrowprops={"arrowstyle": "<->"} ) # Initial state and saturation direction: diff --git a/pyproject.toml b/pyproject.toml index 4aa30dad..93248743 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,11 +51,9 @@ dependencies = [ [project.optional-dependencies] tests = [ - "black", - "flake8", - "hypothesis", - "isort", + "ruff", "mypy", + "hypothesis", "pytest", "pytest-cov", "pytest-mock", @@ -65,7 +63,7 @@ tests = [ docs = [ "autoapi", - "sphinx<7", + "sphinx", "sphinx-argparse", "sphinx-autodoc-typehints", "sphinx_rtd_theme", @@ -79,22 +77,32 @@ Repository = "https://github.com/equinor/pyscal" [project.scripts] pyscal = "pyscal.pyscalcli:main" -[tool.black] + +[tool.ruff] +select=[ + "E", + "F", + "I", + "PIE", + "Q", + "RET", + "RSE", + "SIM", + "W", + "NPY", + # "PD", + # "PL", +] + line-length = 88 -[tool.isort] -profile = "black" -skip = "pyscal/__init__.py" +ignore = ["E741"] [[tool.mypy.overrides]] module = ["numpy.*", "pyscal.version", "pandas.*", "matplotlib.*", "scipy.*", "xlrd.*", "openpyxl.*" ] ignore_missing_imports = true -[tool.pylint] -# Module docstrings are not required, there are other means of documenting at -# that level in subscript -disable = "missing-module-docstring" [tool.pytest.ini_options] norecursedirs = [ diff --git a/pyscal/__init__.py b/pyscal/__init__.py index 0c3f0bb7..02375608 100644 --- a/pyscal/__init__.py +++ b/pyscal/__init__.py @@ -1,5 +1,4 @@ """pyscal""" -# isort: skip_file import logging import sys @@ -16,14 +15,14 @@ def getLogger_pyscal( module_name: str = "pyscal", args_dict: Optional[Dict[str, Union[str, bool]]] = None ) -> logging.Logger: - # pylint: disable=invalid-name """Provide a custom logger for pyscal Logging output is by default split by logging levels (split between WARNING and ERROR) to stdout and stderr, each log occurs in only one of the streams. Args: - module_name: A suggested name for the logger, usually __name__ should be supplied - args_dict: Dictionary with contents from the argparse namespace object containing - only keys "output", "verbose" and "debug". + module_name: A suggested name for the logger, usually __name__ should be + supplied + args_dict: Dictionary with contents from the argparse namespace object + containing only keys "output", "verbose" and "debug". """ logger = logging.getLogger(module_name) if len(logger.handlers) != 0: diff --git a/pyscal/factory.py b/pyscal/factory.py index e7adda22..fee7e002 100644 --- a/pyscal/factory.py +++ b/pyscal/factory.py @@ -27,7 +27,7 @@ def slicedict(dct: dict, keys: Iterable): """Slice a dictionary for a set of keys. Keys not existing will be ignored. """ - return dict((k, dct[k]) for k in keys if k in dct) + return {k: dct[k] for k in keys if k in dct} # Sets of dictionary keys, presence of these @@ -615,13 +615,9 @@ def create_scal_recommendation( params["high"]["h"] = h # Check parameter availability, in order to determine phase configuration - gaswater = all( - sufficient_gas_water_params(params[case]) for case in params.keys() - ) - gasoil = all(sufficient_gas_oil_params(params[case]) for case in params.keys()) - wateroil = all( - sufficient_water_oil_params(params[case]) for case in params.keys() - ) + gaswater = all(sufficient_gas_water_params(params[case]) for case in params) + gasoil = all(sufficient_gas_oil_params(params[case]) for case in params) + wateroil = all(sufficient_water_oil_params(params[case]) for case in params) wog_low: Union[WaterOilGas, GasWater] wog_base: Union[WaterOilGas, GasWater] @@ -660,8 +656,7 @@ def create_scal_recommendation( if errored: raise ValueError("Incomplete SCAL recommendation") - scal = SCALrecommendation(wog_low, wog_base, wog_high, tag) - return scal + return SCALrecommendation(wog_low, wog_base, wog_high, tag) @staticmethod def load_relperm_df( @@ -762,13 +757,11 @@ def load_relperm_df( ignorecasecolumns = ["satnum", "case", "tag", "comment"] for colname in input_df.columns: if colname.lower() in ignorecasecolumns: - input_df.rename( - {colname: colname.upper()}, axis="columns", inplace=True - ) + input_df = input_df.rename({colname: colname.upper()}, axis="columns") # Support both TAG and COLUMN (as TAG) if "COMMENT" in input_df and "TAG" not in input_df: - input_df.rename({"COMMENT": "TAG"}, axis="columns", inplace=True) + input_df = input_df.rename({"COMMENT": "TAG"}, axis="columns") if "COMMENT" in input_df and "TAG" in input_df: # It might never happen that a user puts both tag and comment in # the dataframe, but if so, merge them. @@ -784,10 +777,10 @@ def load_relperm_df( # Delete columns and rows that are all NaNs (this has been observed # to occur from seemingly empty cells in Excel/LibreOffice and # has been seen to vary with Pandas/Openpyxl versions in use) - input_df.dropna(axis="columns", how="all", inplace=True) - input_df.dropna(axis="index", how="all", inplace=True) + input_df = input_df.dropna(axis="columns", how="all") + input_df = input_df.dropna(axis="index", how="all") - if input_df["SATNUM"].isnull().sum() > 0: + if input_df["SATNUM"].isna().sum() > 0: raise ValueError( "Found not-a-number in the SATNUM column. This could be due to " "merged cells in XLSX, which is not supported." @@ -811,7 +804,7 @@ def load_relperm_df( # If we are in a SCAL recommendation setting if "CASE" in input_df: # Enforce lower case: - if input_df["CASE"].isnull().sum() > 0: + if input_df["CASE"].isna().sum() > 0: raise ValueError( "Found not-a-number in the CASE column. This could be due " "merged cells in XLSX, which is not supported." @@ -823,7 +816,7 @@ def load_relperm_df( # Add the SATNUM index to the TAG column if "TAG" not in input_df: input_df["TAG"] = "" - input_df["TAG"].fillna(value="", inplace=True) # Empty cells to empty string. + input_df["TAG"] = input_df["TAG"].fillna(value="") input_df["TAG"] = ( "SATNUM " + input_df["SATNUM"].astype(str) + " " + input_df["TAG"] ) @@ -1117,7 +1110,6 @@ def sufficient_water_oil_params(params: dict, failhard: bool = False) -> bool: True if a WaterOil object should be attempted constructed (but no guarantee for validity of numerical values) """ - # pylint: disable=C1801 # For case insensitiveness, all keys are converted to lower case: params = {key.lower(): value for (key, value) in params.items()} @@ -1153,7 +1145,6 @@ def sufficient_gas_oil_params(params: dict, failhard: bool = False) -> bool: True if a GasOil object should be attempted constructed (but no guarantee for validity of numerical values) """ - # pylint: disable=C1801 # For case insensitiveness, all keys are converted to lower case: params = {key.lower(): value for (key, value) in params.items()} @@ -1188,7 +1179,6 @@ def sufficient_gas_water_params(params: dict, failhard: bool = False) -> bool: True if a GasWater object should be attempted constructed (but no guarantee for validity of numerical values) """ - # pylint: disable=C1801 # For case insensitiveness, all keys are converted to lower case: params = {key.lower(): value for (key, value) in params.items()} @@ -1218,11 +1208,8 @@ def filter_nan_from_dict(params: dict) -> dict: """ cleaned_params = {} for key, value in params.items(): - if isinstance(value, str): + if isinstance(value, str) or not np.isnan(value): cleaned_params[key] = value - else: - if not np.isnan(value): - cleaned_params[key] = value return cleaned_params diff --git a/pyscal/gasoil.py b/pyscal/gasoil.py index 5cca8a96..b8c2a0a4 100644 --- a/pyscal/gasoil.py +++ b/pyscal/gasoil.py @@ -154,7 +154,7 @@ def __init__( sg_list.sort() self.table = pd.DataFrame(sg_list, columns=["SG"]) self.table["sgint"] = list(map(round, self.table["SG"] * SWINTEGERS)) - self.table.drop_duplicates("sgint", inplace=True) + self.table = self.table.drop_duplicates("sgint") # Now sg=1-sorg-swl might be accidentally dropped, so make sure we # have it by replacing the closest value by 1 - sorg exactly @@ -175,7 +175,7 @@ def __init__( drop=True ) - self.table.reset_index(inplace=True) + self.table = self.table.reset_index() self.table = self.table[["SG"]] self.table["SL"] = 1 - self.table["SG"] if krgendanchor == "sorg": @@ -293,9 +293,9 @@ def add_fromtable( ) # Do not extrapolate this data. We will bfill and ffill afterwards self.table["KRG"] = pchip(self.table["SG"], extrapolate=False) - self.table["KRG"].fillna(method="ffill", inplace=True) - self.table["KRG"].fillna(method="bfill", inplace=True) - self.table["KRG"].clip(lower=0.0, upper=1.0, inplace=True) + self.table["KRG"] = self.table["KRG"].fillna(method="ffill") + self.table["KRG"] = self.table["KRG"].fillna(method="bfill") + self.table["KRG"] = self.table["KRG"].clip(lower=0.0, upper=1.0) self.krgcomment = "-- krg from tabular input" + krgcomment + "\n" self.sgcr = self.estimate_sgcr() if krogcolname in dframe: @@ -309,9 +309,9 @@ def add_fromtable( dframe[sgcolname].astype(float), dframe[krogcolname].astype(float) ) self.table["KROG"] = pchip(self.table["SG"], extrapolate=False) - self.table["KROG"].fillna(method="ffill", inplace=True) - self.table["KROG"].fillna(method="bfill", inplace=True) - self.table["KROG"].clip(lower=0.0, upper=1.0, inplace=True) + self.table["KROG"] = self.table["KROG"].fillna(method="ffill") + self.table["KROG"] = self.table["KROG"].fillna(method="bfill") + self.table["KROG"] = self.table["KROG"].clip(lower=0.0, upper=1.0) self.krogcomment = "-- krog from tabular input" + krogcomment + "\n" self.sorg = self.estimate_sorg() @@ -347,11 +347,13 @@ def add_fromtable( ) ) dframe = dframe.replace([np.inf, -np.inf], np.nan) - dframe.dropna(subset=[pccolname], how="all", inplace=True) + dframe = dframe.dropna(subset=[pccolname], how="all") # If nonzero, then it must be increasing: - if dframe[pccolname].abs().sum() > 0: - if not (dframe[pccolname].diff().dropna() > 0.0).all(): - raise ValueError("Incoming pc not increasing") + if ( + dframe[pccolname].abs().sum() > 0 + and not (dframe[pccolname].diff().dropna() > 0.0).all() + ): + raise ValueError("Incoming pc not increasing") pchip = PchipInterpolator( dframe[sgcolname].astype(float), dframe[pccolname].astype(float) ) @@ -539,7 +541,6 @@ def add_LET_gas( """ # Similar code in wateroil.add_LET_water, but readability # is better by having them separate - # pylint: disable=duplicate-code assert epsilon < l < MAX_EXPONENT_KR assert epsilon < e < MAX_EXPONENT_KR assert epsilon < t < MAX_EXPONENT_KR @@ -724,10 +725,13 @@ def selfcheck(self, mode: str = "SGOF") -> bool: if "KRG" in self.table and not np.isclose(min(self.table["KRG"]), 0.0): logger.error("KRG must start at zero") error = True - if "PC" in self.table and self.table["PC"][0] > -epsilon: - if not (self.table["PC"].diff().dropna() < epsilon).all(): - logger.error("PC data for gas-oil not strictly decreasing") - error = True + if ( + "PC" in self.table + and self.table["PC"][0] > -epsilon + and not (self.table["PC"].diff().dropna() < epsilon).all() + ): + logger.error("PC data for gas-oil not strictly decreasing") + error = True if "PC" in self.table and np.isinf(self.table["PC"].max()): logger.error("PC goes to infinity for gas-oil. ") error = True @@ -735,7 +739,7 @@ def selfcheck(self, mode: str = "SGOF") -> bool: logger.error("pc data contains NaN") error = True - for col in list(set(["SG", "KRG", "KROG"]) & set(self.table.columns)): + for col in list({"SG", "KRG", "KROG"} & set(self.table.columns)): if not ( (min(self.table[col]) >= -epsilon) and (max(self.table[col]) <= 1 + epsilon) @@ -813,14 +817,13 @@ def slgof_df(self) -> pd.DataFrame: if "PC" not in self.table.columns: # Only happens when the SLGOF function is skipped (test code) self.table["PC"] = 0.0 - slgof = ( + return ( self.table[ self.table["SG"] <= 1 - self.sorg - self.swl + 1.0 / float(SWINTEGERS) ] .sort_values("SL")[["SL", "KRG", "KROG", "PC"]] .reset_index(drop=True) ) - return slgof def SLGOF(self, header: bool = True, dataincommentrow: bool = True) -> str: """Produce SLGOF input for Eclipse reservoir simulator. @@ -1021,7 +1024,6 @@ def plotkrgkrog( matplotlib axis to plot on, if None, a fresh plot will be made. """ - # pylint: disable=import-outside-toplevel # Lazy import of matplotlib for speed reasons import matplotlib import matplotlib.pyplot as plt diff --git a/pyscal/gaswater.py b/pyscal/gaswater.py index 750eaed3..190af2c1 100644 --- a/pyscal/gaswater.py +++ b/pyscal/gaswater.py @@ -292,8 +292,8 @@ def crosspoint(self) -> Optional[float]: # The "SL" column in the GasOil object corresponds exactly to "SW" in WaterOil # but since they are floating point, we do not want to "merge" dataframes on it, # rather concatenate and let linear interpolation fill in values. - dframe["SW"].fillna(value=0, inplace=True) - dframe["SL"].fillna(value=0, inplace=True) + dframe["SW"] = dframe["SW"].fillna(value=0) + dframe["SL"] = dframe["SL"].fillna(value=0) dframe["sat"] = dframe["SL"] + dframe["SW"] dframe = ( dframe.set_index("sat") @@ -321,7 +321,6 @@ def plotkrwkrg( window will be made. If supplied, it will draw on the specified axis.""" - # pylint: disable=import-outside-toplevel # Lazy import of matplotlib for speed reasons. import matplotlib import matplotlib.pyplot as plt diff --git a/pyscal/plotting.py b/pyscal/plotting.py index f29020e5..53048f92 100644 --- a/pyscal/plotting.py +++ b/pyscal/plotting.py @@ -86,15 +86,15 @@ def format_gaswater_table(model: GasWater) -> pd.DataFrame: """ gasoil = model.gasoil.table[["SL", "KRG"]].copy() - gasoil.rename(columns={"SL": "SW"}, inplace=True) + gasoil = gasoil.rename(columns={"SL": "SW"}) gasoil["SG"] = 1 - gasoil["SW"] wateroil = model.wateroil.table[["SW", "KRW", "PC"]].copy() # Sort by SW to be able to join on index - gasoil.sort_values("SW", ascending=True, inplace=True) - wateroil.sort_values("SW", ascending=True, inplace=True) - gasoil.reset_index(inplace=True, drop=True) - wateroil.reset_index(inplace=True, drop=True) + gasoil = gasoil.sort_values("SW", ascending=True) + wateroil = wateroil.sort_values("SW", ascending=True) + gasoil = gasoil.reset_index(drop=True) + wateroil = wateroil.reset_index(drop=True) # Check if SW in the two models differs using an epsilon of 1E-6 If any # absolute differences are greater than this threshold, an assertion error @@ -105,10 +105,8 @@ def format_gaswater_table(model: GasWater) -> pd.DataFrame: # Merge dataframes and format gaswater = gasoil.merge(wateroil, left_index=True, right_index=True) - gaswater.rename(columns={"SW_x": "SW"}, inplace=True) - gaswater.drop("SW_y", axis=1, inplace=True) - - return gaswater + gaswater = gaswater.rename(columns={"SW_x": "SW"}) + return gaswater.drop("SW_y", axis=1) def get_satnum_from_tag(string: str) -> int: @@ -121,8 +119,7 @@ def get_satnum_from_tag(string: str) -> int: Returns: int: SATNUM number """ - satnum = int(string.split("SATNUM")[1].strip()) - return satnum + return int(string.split("SATNUM")[1].strip()) def get_plot_config_options(curve_type: str, **kwargs) -> dict: @@ -140,10 +137,7 @@ def get_plot_config_options(curve_type: str, **kwargs) -> dict: config = PLOT_CONFIG_OPTIONS[curve_type].copy() # If semilog plot, add suffix to the name of the saved relperm figure - if kwargs["semilog"]: - suffix = "_semilog" - else: - suffix = "" + suffix = "_semilog" if kwargs["semilog"] else "" config["suffix"] = suffix @@ -295,9 +289,7 @@ def plot_relperm( color=config["krb_colour"], ) - fig = format_relperm_plot(fig, **kwargs, **config) - - return fig + return format_relperm_plot(fig, **kwargs, **config) def save_figure( diff --git a/pyscal/pyscalcli.py b/pyscal/pyscalcli.py index 50abc275..02997b72 100644 --- a/pyscal/pyscalcli.py +++ b/pyscal/pyscalcli.py @@ -304,10 +304,7 @@ def pyscal_main( parametertable, h=delta_s ) # can be both water-oil, water-oil-gas, or gas-water - if family2 or wog_list.pyscaltype == GasWater: - family = 2 - else: - family = 1 + family = 2 if family2 or wog_list.pyscaltype == GasWater else 1 if output == "-": print(wog_list.build_eclipse_data(family=family, slgof=slgof)) diff --git a/pyscal/pyscallist.py b/pyscal/pyscallist.py index 11acdf26..2c775309 100644 --- a/pyscal/pyscallist.py +++ b/pyscal/pyscallist.py @@ -206,7 +206,7 @@ def df(self) -> pd.DataFrame: dframe = pd.concat(df_list, sort=False, ignore_index=True) sort_rows_on = [colname for colname in sort_candidates if colname in dframe] if sort_rows_on: - dframe.sort_values(sort_rows_on, inplace=True) + dframe = dframe.sort_values(sort_rows_on) return dframe def relevant_keywords(self, family: int = 1, slgof: bool = False) -> List[str]: @@ -339,12 +339,13 @@ def interpolate( ) if isinstance(int_params_wo, (float, int)): int_params_wo = [int_params_wo] * self.__len__() - if isinstance(int_params_wo, list) and len(int_params_wo) == 1: + elif isinstance(int_params_wo, list) and len(int_params_wo) == 1: int_params_wo = int_params_wo * self.__len__() if int_params_go is None or isinstance(int_params_go, (float, int)): int_params_go = [int_params_go] * len(self) - if isinstance(int_params_go, list) and len(int_params_go) == 1: + elif isinstance(int_params_go, list) and len(int_params_go) == 1: int_params_go = int_params_go * self.__len__() + if 1 < len(int_params_wo) < len(self): raise ValueError( f"Too few interpolation parameters given for WaterOil {int_params_wo}" diff --git a/pyscal/scalrecommendation.py b/pyscal/scalrecommendation.py index a255ad98..0d3d9e00 100644 --- a/pyscal/scalrecommendation.py +++ b/pyscal/scalrecommendation.py @@ -140,10 +140,7 @@ def interpolate( need to be the same as the tables interpolation is done from. """ - if parameter2 is not None: - gasparameter = parameter2 - else: - gasparameter = parameter + gasparameter = parameter2 if parameter2 is not None else parameter # Either wateroil or gasoil can be None in the low, base, high # If they are None, it is a two-phase problem and we @@ -181,20 +178,18 @@ def interpolate( assert self.base.wateroil is not None assert self.high.wateroil is not None tags = tags.union( - set( - [ - self.base.wateroil.tag, - self.low.wateroil.tag, - self.high.wateroil.tag, - ] - ) + { + self.base.wateroil.tag, + self.low.wateroil.tag, + self.high.wateroil.tag, + } ) if do_gasoil: assert self.low.gasoil is not None assert self.base.gasoil is not None assert self.high.gasoil is not None tags = tags.union( - set([self.base.gasoil.tag, self.low.gasoil.tag, self.high.gasoil.tag]) + {self.base.gasoil.tag, self.low.gasoil.tag, self.high.gasoil.tag} ) tagstring = "\n".join(tags) if do_gaswater: diff --git a/pyscal/utils/capillarypressure.py b/pyscal/utils/capillarypressure.py index 337fb923..82d34924 100644 --- a/pyscal/utils/capillarypressure.py +++ b/pyscal/utils/capillarypressure.py @@ -15,7 +15,6 @@ def simple_J( drho: float, g: float = 9.81, ) -> float: # Union[float, Iterable[float]]: - # pylint: disable=invalid-name,anomalous-backslash-in-string r"""Calculate capillary pressure with bar as unit RMS version: @@ -47,7 +46,7 @@ def simple_J( Returns: capillary pressure, same type as swnpc input argument. - """ # noqa + """ assert g >= 0 assert b < MAX_EXPONENT_PC assert b > -MAX_EXPONENT_PC @@ -75,21 +74,18 @@ def _height_to_pc(height: float, drho: float, g: float) -> float: def _sw_to_simpleJ(sw: float, a: float, b: float) -> float: - # pylint: disable=invalid-name """Convert a water saturation value to the associated J-value, using RMS simple-J""" return float(a) * sw ** float(b) def _simpleJ_to_sw(J: float, a: float, b: float) -> float: - # pylint: disable=invalid-name """Convert a J-function-value to a water saturation value, using RMS simple-J""" return math.pow(J / float(a), 1.0 / float(b)) def _simpleJ_to_height(J: float, poro_ref: float, perm_ref: float) -> float: - # pylint: disable=invalid-name """Convert a J-function value to a height-value in meters This scales the J-value with the inverse of characteristic @@ -106,7 +102,6 @@ def _simpleJ_to_height(J: float, poro_ref: float, perm_ref: float) -> float: def _height_to_simpleJ(H: float, poro_ref: float, perm_ref: float): - # pylint: disable=invalid-name """Convert a height value (in meters) to a corresponding J-function This scales the J-value with the characteristic @@ -125,7 +120,7 @@ def _height_to_simpleJ(H: float, poro_ref: float, perm_ref: float): def swl_from_height_simpleJ( swlheight: float, swirr: float, a: float, b: float, poro_ref: float, perm_ref: float ) -> float: - # pylint: disable=invalid-name + # disable=invalid-name """Calculate a swl value based on a height parameter. The height parameter is typically meters above free water level (FWL) diff --git a/pyscal/utils/monotonicity.py b/pyscal/utils/monotonicity.py index 29baba78..51d1cd90 100644 --- a/pyscal/utils/monotonicity.py +++ b/pyscal/utils/monotonicity.py @@ -4,7 +4,6 @@ import sys from typing import Dict, List, Union -# pylint: disable=wrong-import-position if sys.version_info >= (3, 8): from typing import TypedDict else: @@ -171,13 +170,11 @@ def clip_accumulate( else: series = np.minimum.accumulate(series) if "lower" in monotonicity and "upper" in monotonicity: - series.clip( - lower=monotonicity["lower"], upper=monotonicity["upper"], inplace=True - ) + series = series.clip(lower=monotonicity["lower"], upper=monotonicity["upper"]) elif "lower" in monotonicity: - series.clip(lower=monotonicity["lower"], inplace=True) + series = series.clip(lower=monotonicity["lower"]) elif "upper" in monotonicity: - series.clip(upper=monotonicity["upper"], inplace=True) + series = series.clip(upper=monotonicity["upper"]) return series @@ -303,8 +300,8 @@ def validate_monotonicity_arg( if abs(signvalue) > 1: raise ValueError("Monotonocity sign must be -1 or +1, not larger/smaller") - if "allowzero" in monotonicity[col]: - if monotonicity[col]["allowzero"] not in {True, False}: - raise ValueError( - "allowzero in monotonicity argument must be True/False" - ) + if "allowzero" in monotonicity[col] and monotonicity[col]["allowzero"] not in { + True, + False, + }: + raise ValueError("allowzero in monotonicity argument must be True/False") diff --git a/pyscal/utils/relperm.py b/pyscal/utils/relperm.py index 381c0e1e..35c348db 100644 --- a/pyscal/utils/relperm.py +++ b/pyscal/utils/relperm.py @@ -58,7 +58,7 @@ def crosspoint(dframe: pd.DataFrame, satcol: str, kr1col: str, kr2col: str) -> f cross_dframe = cross_dframe[~cross_dframe.index.duplicated(keep="first")] if cross_dframe.shape[0] > 2: - cross_dframe.interpolate(method="slinear", inplace=True) + cross_dframe = cross_dframe.interpolate(method="slinear") if cross_dframe.isna().any().any(): logger.error("Could not compute crosspoint)") diff --git a/pyscal/utils/testing.py b/pyscal/utils/testing.py index 29e9e851..e77ab6d0 100644 --- a/pyscal/utils/testing.py +++ b/pyscal/utils/testing.py @@ -1,17 +1,16 @@ """Common functions and mock data for usage in pyscal testing""" import io +from contextlib import suppress from typing import Union import numpy as np import pandas as pd -try: - from hypothesis import settings -except ModuleNotFoundError: +with suppress(ModuleNotFoundError): # This module is only needed for testing, but this testing module # should be importable in other scenarios as well. - pass + from hypothesis import settings from pyscal import GasOil, WaterOil @@ -60,13 +59,7 @@ def sat_table_str_ok(sat_table_str: str) -> None: for line in sat_table_str.splitlines(): try: - if not ( - not line - or line.startswith("S") - or line.startswith("--") - or line.startswith("/") - or int(line[0]) >= 0 - ): + if not (not line or line.startswith(("S", "--", "/")) or int(line[0]) >= 0): assert False except ValueError as e_msg: diff --git a/pyscal/wateroil.py b/pyscal/wateroil.py index 5ce08288..27a9ec74 100644 --- a/pyscal/wateroil.py +++ b/pyscal/wateroil.py @@ -162,7 +162,7 @@ def __init__( # Ensure that we do not have sw values that are too close # to each other, determined rougly by the distance 1/10000 self.table["swint"] = list(map(round, self.table["SW"] * SWINTEGERS)) - self.table.drop_duplicates("swint", inplace=True) + self.table = self.table.drop_duplicates("swint") # Now, sw=1-sorw might be accidentaly dropped, so make sure we # have it by replacing the closest value by 1-sorw exactly @@ -181,9 +181,9 @@ def __init__( if not np.isclose(self.table["SW"].max(), 1.0 - self.sgl): # Add it as an extra row: self.table.loc[len(self.table) + 1, "SW"] = 1.0 - self.sgl - self.table.sort_values(by="SW", inplace=True) + self.table = self.table.sort_values(by="SW") - self.table.reset_index(inplace=True) + self.table = self.table.reset_index() self.table = self.table[["SW"]] # Drop the swint column # Normalize for krw: @@ -346,7 +346,7 @@ def add_fromtable( ] = linearinterpolator( self.table.loc[self.table["SW"] >= 1 - sorw, "SW"] ) - self.table["KRW"].clip(lower=0.0, upper=1.0, inplace=True) + self.table["KRW"] = self.table["KRW"].clip(lower=0.0, upper=1.0) self.sorw = sorw self.krwcomment = "-- krw from tabular input" + krwcomment + "\n" self.swcr = self.estimate_swcr() @@ -397,7 +397,7 @@ def add_fromtable( ] = linearinterpolator( self.table.loc[self.table["SW"] >= 1 - socr, "SW"] ) - self.table["KROW"].clip(lower=0.0, upper=1.0, inplace=True) + self.table["KROW"] = self.table["KROW"].clip(lower=0.0, upper=1.0) self.socr = socr self.krowcomment = "-- krow from tabular input" + krowcomment + "\n" if pccolname in dframe: @@ -414,11 +414,13 @@ def add_fromtable( ) ) dframe = dframe.replace([np.inf, -np.inf], np.nan) - dframe.dropna(subset=[pccolname], how="all", inplace=True) + dframe = dframe.dropna(subset=[pccolname], how="all") # If nonzero, then it must be decreasing: - if dframe[pccolname].abs().sum() > 0: - if not (dframe[pccolname].diff().dropna() < 0.0).all(): - raise ValueError("Incoming pc not decreasing") + if ( + dframe[pccolname].abs().sum() > 0 + and not (dframe[pccolname].diff().dropna() < 0.0).all() + ): + raise ValueError("Incoming pc not decreasing") pchip = PchipInterpolator( dframe[swcolname].astype(float), dframe[pccolname].astype(float) ) @@ -548,7 +550,6 @@ def add_LET_water( """ # Similar code in gasoil.add_LET_gas, but readability is # better by having them separate. - # pylint: disable=duplicate-code assert epsilon < l < MAX_EXPONENT_KR assert epsilon < e < MAX_EXPONENT_KR assert epsilon < t < MAX_EXPONENT_KR @@ -646,7 +647,6 @@ def add_simple_J( drho: float = 300, g: float = 9.81, ) -> None: - # pylint: disable=anomalous-backslash-in-string r"""Add capillary pressure function from a simplified J-function This is the RMS version of the coefficients *a* and *b*, the formula @@ -680,7 +680,7 @@ def add_simple_J( Returns: None. Modifies pc column in self.table, using bar as pressure unit. - """ # noqa + """ assert g >= 0 assert b < MAX_EXPONENT_PC assert b > -MAX_EXPONENT_PC @@ -719,7 +719,6 @@ def add_simple_J_petro( drho: float = 300, g: float = 9.81, ) -> None: - # pylint: disable=anomalous-backslash-in-string r"""Add capillary pressure function from a simplified J-function This is the *petrophysical* version of the coefficients *a* and *b*, the formula @@ -753,7 +752,7 @@ def add_simple_J_petro( Returns: None. Modifies pc column in self.table, using bar as pressure unit. - """ # noqa + """ assert g >= 0 assert b < MAX_EXPONENT_PC assert b > -MAX_EXPONENT_PC @@ -788,7 +787,6 @@ def add_normalized_J( ) -> None: # Don't make this a raw string to avoid the \l warning, # it destroys the Latex-formatting in sphinx - # pylint: disable=anomalous-backslash-in-string r""" Add capillary pressure in bar through a normalized J-function. @@ -809,7 +807,7 @@ def add_normalized_J( Returns: None. Modifies pc column in self.table, using bar as pressure unit. - """ # noqa + """ assert epsilon < abs(a) < MAX_EXPONENT_PC assert epsilon < abs(b) < MAX_EXPONENT_PC assert epsilon < poro <= 1.0 @@ -859,7 +857,6 @@ def add_skjaeveland_pc( swr: Optional[float] = None, sor: Optional[float] = None, ): - # pylint: disable=line-too-long """Add capillary pressure from the Skjæveland correlation, Doc: https://wiki.equinor.com/wiki/index.php/Res:The_Skjaeveland_correlation_for_capillary_pressure @@ -874,7 +871,7 @@ def add_skjaeveland_pc( Modifies or adds self.table["PC"] if succesful. Returns false if error occured. - """ # noqa + """ if cw < 0: raise ValueError("cw must be larger or equal to zero") if co > 0: @@ -919,7 +916,7 @@ def add_skjaeveland_pc( # From 1-sor, the pc is not defined. Extrapolate constantly, and let # the non-monotonicity be fixed in the output generators. - self.table["PC"].fillna(method="ffill", inplace=True) + self.table["PC"] = self.table["PC"].fillna(method="ffill") def add_LET_pc_pd( self, @@ -932,14 +929,13 @@ def add_LET_pc_pd( Pcmax: float, Pct: float, ) -> None: - # pylint: disable=line-too-long """Add a primary drainage LET capillary pressure curve. Docs: https://wiki.equinor.com/wiki/index.php/Res:The_LET_correlation_for_capillary_pressure Note that Pc where Sw > 1 - sorw will appear linear because there are no saturation points in that interval. - """ # noqa + """ assert epsilon < Lp < MAX_EXPONENT_PC assert epsilon < Ep < MAX_EXPONENT_PC assert epsilon < Tp < MAX_EXPONENT_PC @@ -984,11 +980,10 @@ def add_LET_pc_imb( Pcmin: float, Pct: float, ) -> None: - # pylint: disable=line-too-long """Add an imbition LET capillary pressure curve. Docs: https://wiki.equinor.com/wiki/index.php/Res:The_LET_correlation_for_capillary_pressure - """ # noqa + """ assert epsilon < Ls < MAX_EXPONENT_PC assert epsilon < Es < MAX_EXPONENT_PC assert epsilon < Ts < MAX_EXPONENT_PC @@ -1139,17 +1134,20 @@ def selfcheck(self, mode: str = "SWOF") -> bool: # be the users responsibility. logger.error("KROW data not level or monotonically decreasing") error = True - if "PC" in self.table.columns and self.table["PC"][0] > -epsilon: - if not (self.table["PC"].diff().dropna().round(10) < epsilon).all(): - logger.error("PC data not strictly decreasing") - error = True + if ( + "PC" in self.table.columns + and self.table["PC"][0] > -epsilon + and not (self.table["PC"].diff().dropna().round(10) < epsilon).all() + ): + logger.error("PC data not strictly decreasing") + error = True if "PC" in self.table.columns and np.isnan(self.table["PC"]).any(): logger.error("pc data contains NaN") error = True if "PC" in self.table.columns and np.isinf(self.table["PC"].max()): logger.error("pc goes to infinity. Maybe swirr=swl?") error = True - for col in list(set(["SW", "KRW", "KROW"]) & set(self.table.columns)): + for col in list({"SW", "KRW", "KROW"} & set(self.table.columns)): if not ( (round(min(self.table[col]), 10) >= -epsilon) and (round(max(self.table[col]), 10) <= 1 + epsilon) @@ -1345,7 +1343,6 @@ def plotpc( If mpl_ax is supplied, the curve will be drawn on that, if not, a new axis (plot) will be made """ - # pylint: disable=import-outside-toplevel # Lazy import for speed reaons. import matplotlib import matplotlib.pyplot as plt @@ -1388,7 +1385,6 @@ def plotkrwkrow( If the argument 'mpl_ax' is not supplied, a new plot window will be made. If supplied, it will draw on the specified axis.""" - # pylint: disable=import-outside-toplevel # Lazy import for speed reaons. import matplotlib import matplotlib.pyplot as plt diff --git a/pyscal/wateroilgas.py b/pyscal/wateroilgas.py index 27d09e48..7203b4d9 100644 --- a/pyscal/wateroilgas.py +++ b/pyscal/wateroilgas.py @@ -166,7 +166,7 @@ def SOF3(self, header: bool = True, dataincommentrow: bool = True) -> str: .reset_index() ) sof3table["soint"] = list(map(round, sof3table["SO"] * SWINTEGERS)) - sof3table.drop_duplicates("soint", inplace=True) + sof3table = sof3table.drop_duplicates("soint") # The 'so' column has been calculated from floating point numbers # and the zero value easily becomes a negative zero, circumvent this: diff --git a/tests/test_factory.py b/tests/test_factory.py index fcdf3ca2..b77eef8d 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -28,23 +28,22 @@ def test_factory_wateroil(): with pytest.raises(TypeError): # (it must be a dictionary) - # pylint: disable=unexpected-keyword-arg - pyscal_factory.create_water_oil(swirr=0.01) # noqa + pyscal_factory.create_water_oil(swirr=0.01) with pytest.raises(TypeError): pyscal_factory.create_water_oil(params="swirr 0.01") wateroil = pyscal_factory.create_water_oil( - dict( - swirr=0.01, - swl=0.1, - bogus="foobar", - tag="Good sand", - nw=3, - now=2, - krwend=0.2, - krwmax=0.5, - ) + { + "swirr": 0.01, + "swl": 0.1, + "bogus": "foobar", + "tag": "Good sand", + "nw": 3, + "now": 2, + "krwend": 0.2, + "krwmax": 0.5, + } ) assert isinstance(wateroil, WaterOil) assert wateroil.swirr == 0.01 @@ -58,7 +57,7 @@ def test_factory_wateroil(): sat_table_str_ok(wateroil.SWFN()) wateroil = pyscal_factory.create_water_oil( - dict(nw=3, now=2, sorw=0.1, krwend=0.2, krwmax=0.5) + {"nw": 3, "now": 2, "sorw": 0.1, "krwend": 0.2, "krwmax": 0.5} ) assert isinstance(wateroil, WaterOil) assert "KRW" in wateroil.table @@ -70,7 +69,9 @@ def test_factory_wateroil(): # Ambiguous works, but we don't guarantee that this results # in LET or Corey. - wateroil = pyscal_factory.create_water_oil(dict(nw=3, Lw=2, Ew=2, Tw=2, now=3)) + wateroil = pyscal_factory.create_water_oil( + {"nw": 3, "Lw": 2, "Ew": 2, "Tw": 2, "now": 3} + ) assert "KRW" in wateroil.table assert "Corey" in wateroil.krwcomment or "LET" in wateroil.krwcomment check_table(wateroil.table) @@ -78,7 +79,9 @@ def test_factory_wateroil(): sat_table_str_ok(wateroil.SWFN()) # Mixing Corey and LET - wateroil = pyscal_factory.create_water_oil(dict(Lw=2, Ew=2, Tw=2, krwend=1, now=4)) + wateroil = pyscal_factory.create_water_oil( + {"Lw": 2, "Ew": 2, "Tw": 2, "krwend": 1, "now": 4} + ) assert isinstance(wateroil, WaterOil) assert "KRW" in wateroil.table assert wateroil.table["KRW"].max() == 1.0 @@ -88,7 +91,7 @@ def test_factory_wateroil(): sat_table_str_ok(wateroil.SWFN()) wateroil = pyscal_factory.create_water_oil( - dict(Lw=2, Ew=2, Tw=2, Low=3, Eow=3, Tow=3, krwend=0.5) + {"Lw": 2, "Ew": 2, "Tw": 2, "Low": 3, "Eow": 3, "Tow": 3, "krwend": 0.5} ) assert isinstance(wateroil, WaterOil) assert "KRW" in wateroil.table @@ -103,7 +106,16 @@ def test_factory_wateroil(): # Add capillary pressure wateroil = pyscal_factory.create_water_oil( - dict(swl=0.1, nw=1, now=1, a=2, b=-1, poro_ref=0.2, perm_ref=100, drho=200) + { + "swl": 0.1, + "nw": 1, + "now": 1, + "a": 2, + "b": -1, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) assert "PC" in wateroil.table assert wateroil.table["PC"].max() > 0.0 @@ -114,7 +126,17 @@ def test_factory_wateroil(): # Test that the optional gravity g is picked up: wateroil = pyscal_factory.create_water_oil( - dict(swl=0.1, nw=1, now=1, a=2, b=-1, poro_ref=0.2, perm_ref=100, drho=200, g=0) + { + "swl": 0.1, + "nw": 1, + "now": 1, + "a": 2, + "b": -1, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + "g": 0, + } ) assert "PC" in wateroil.table assert wateroil.table["PC"].max() == 0.0 @@ -124,16 +146,16 @@ def test_factory_wateroil(): # Test petrophysical simple J: wateroil = pyscal_factory.create_water_oil( - dict( - swl=0.1, - nw=1, - now=1, - a_petro=2, - b_petro=-1, - poro_ref=0.2, - perm_ref=100, - drho=200, - ) + { + "swl": 0.1, + "nw": 1, + "now": 1, + "a_petro": 2, + "b_petro": -1, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) assert "PC" in wateroil.table assert wateroil.table["PC"].max() > 0.0 @@ -144,7 +166,16 @@ def test_factory_wateroil(): # One pc param missing: wateroil = pyscal_factory.create_water_oil( - dict(swl=0.1, nw=1, now=1, a=2, b=-1, perm_ref=100, drho=200, g=0) + { + "swl": 0.1, + "nw": 1, + "now": 1, + "a": 2, + "b": -1, + "perm_ref": 100, + "drho": 200, + "g": 0, + } ) assert "PC" not in wateroil.table @@ -199,17 +230,17 @@ def test_init_with_swlheight(): when initializing the WaterOil object""" pyscal_factory = PyscalFactory() wateroil = pyscal_factory.create_water_oil( - dict( - swlheight=200, - nw=1, - now=1, - swirr=0.01, - a=1, - b=-2, - poro_ref=0.2, - perm_ref=100, - drho=200, - ) + { + "swlheight": 200, + "nw": 1, + "now": 1, + "swirr": 0.01, + "a": 1, + "b": -2, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) assert np.isclose(wateroil.swl, 0.02480395) assert "swl=0.024" in wateroil.SWOF() @@ -219,55 +250,55 @@ def test_init_with_swlheight(): match="Can't initialize from SWLHEIGHT without sufficient simple-J parameters", ): # This should fail because capillary pressure parameters are not provided. - pyscal_factory.create_water_oil(dict(swlheight=200, nw=1, now=1)) + pyscal_factory.create_water_oil({"swlheight": 200, "nw": 1, "now": 1}) # swcr must be larger than swl: with pytest.raises(ValueError, match="lower than computed swl"): pyscal_factory.create_water_oil( - dict( - swlheight=200, - nw=1, - now=1, - swirr=0.01, - swcr=0.0101, - a=1, - b=-2, - poro_ref=0.2, - perm_ref=100, - drho=200, - ) + { + "swlheight": 200, + "nw": 1, + "now": 1, + "swirr": 0.01, + "swcr": 0.0101, + "a": 1, + "b": -2, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) # swlheight must be positive: with pytest.raises(ValueError, match="swlheight must be larger than zero"): pyscal_factory.create_water_oil( - dict( - swlheight=-200, - nw=1, - now=1, - swirr=0.01, - a=1, - b=-2, - poro_ref=0.2, - perm_ref=100, - drho=200, - ) + { + "swlheight": -200, + "nw": 1, + "now": 1, + "swirr": 0.01, + "a": 1, + "b": -2, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) # If swcr is large enough, it will pass: wateroil = pyscal_factory.create_water_oil( - dict( - swlheight=200, - nw=1, - now=1, - swirr=0.01, - swcr=0.3, - a=1, - b=-2, - poro_ref=0.2, - perm_ref=100, - drho=200, - ) + { + "swlheight": 200, + "nw": 1, + "now": 1, + "swirr": 0.01, + "swcr": 0.3, + "a": 1, + "b": -2, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) assert wateroil.swcr > wateroil.swl assert wateroil.swcr == 0.3 @@ -275,18 +306,18 @@ def test_init_with_swlheight(): # Test that GasWater also can be initialized with swlheight: gaswater = pyscal_factory.create_gas_water( - dict( - swlheight=200, - nw=1, - ng=1, - swirr=0.01, - swcr=0.3, - a=1, - b=-2, - poro_ref=0.2, - perm_ref=100, - drho=200, - ) + { + "swlheight": 200, + "nw": 1, + "ng": 1, + "swirr": 0.01, + "swcr": 0.3, + "a": 1, + "b": -2, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) assert "swl=0.024" in gaswater.SWFN() assert gaswater.swcr > gaswater.swl @@ -298,16 +329,16 @@ def test_init_with_swlheight(): ValueError, match="Can't initialize from SWLHEIGHT without sufficient simple-J" ): pyscal_factory.create_water_oil( - dict( - swlheight=200, - nw=1, - now=1, - a=1, - b=-2, - poro_ref=0.2, - perm_ref=100, - drho=200, - ) + { + "swlheight": 200, + "nw": 1, + "now": 1, + "a": 1, + "b": -2, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) @@ -318,47 +349,49 @@ def test_relative_swcr(): pyscal_factory = PyscalFactory() with pytest.raises(ValueError, match="swl must be provided"): - pyscal_factory.create_water_oil(dict(swcr_add=0.1, nw=1, now=1, swirr=0.01)) + pyscal_factory.create_water_oil( + {"swcr_add": 0.1, "nw": 1, "now": 1, "swirr": 0.01} + ) with pytest.raises(ValueError, match="swcr and swcr_add at the same time"): pyscal_factory.create_water_oil( - dict(swcr_add=0.1, swcr=0.1, swl=0.1, nw=1, now=1, swirr=0.01) + {"swcr_add": 0.1, "swcr": 0.1, "swl": 0.1, "nw": 1, "now": 1, "swirr": 0.01} ) wateroil = pyscal_factory.create_water_oil( - dict(swcr_add=0.1, swl=0.1, nw=1, now=1, swirr=0.01) + {"swcr_add": 0.1, "swl": 0.1, "nw": 1, "now": 1, "swirr": 0.01} ) assert wateroil.swcr == 0.2 # Test when relative to swlheight: wateroil = pyscal_factory.create_water_oil( - dict( - swlheight=200, - swcr_add=0.01, - nw=1, - now=1, - swirr=0.01, - a=1, - b=-2, - poro_ref=0.2, - perm_ref=100, - drho=200, - ) + { + "swlheight": 200, + "swcr_add": 0.01, + "nw": 1, + "now": 1, + "swirr": 0.01, + "a": 1, + "b": -2, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) assert np.isclose(wateroil.swl, 0.02480395) assert np.isclose(wateroil.swcr, 0.02480395 + 0.01) gaswater = pyscal_factory.create_gas_water( - dict( - swlheight=200, - nw=1, - ng=1, - swirr=0.01, - swcr_add=0.1, - a=1, - b=-2, - poro_ref=0.2, - perm_ref=100, - drho=200, - ) + { + "swlheight": 200, + "nw": 1, + "ng": 1, + "swirr": 0.01, + "swcr_add": 0.1, + "a": 1, + "b": -2, + "poro_ref": 0.2, + "perm_ref": 100, + "drho": 200, + } ) assert np.isclose(gaswater.swl, 0.02480395) assert np.isclose(gaswater.swcr, 0.02480395 + 0.1) @@ -369,7 +402,7 @@ def test_ambiguity(): parameters""" pyscal_factory = PyscalFactory() wateroil = pyscal_factory.create_water_oil( - dict(swl=0.1, nw=10, Lw=1, Ew=1, Tw=1, now=2, h=0.1, no=2) + {"swl": 0.1, "nw": 10, "Lw": 1, "Ew": 1, "Tw": 1, "now": 2, "h": 0.1, "no": 2} ) # Corey is picked here. assert "Corey" in wateroil.krwcomment @@ -386,14 +419,13 @@ def test_factory_gasoil(): with pytest.raises(TypeError): # (this must be a dictionary) - # pylint: disable=unexpected-keyword-arg - pyscal_factory.create_gas_oil(swirr=0.01) # noqa + pyscal_factory.create_gas_oil(swirr=0.01) with pytest.raises(TypeError): pyscal_factory.create_gas_oil(params="swirr 0.01") gasoil = pyscal_factory.create_gas_oil( - dict(swirr=0.01, swl=0.1, sgcr=0.05, tag="Good sand", ng=1, nog=2) + {"swirr": 0.01, "swl": 0.1, "sgcr": 0.05, "tag": "Good sand", "ng": 1, "nog": 2} ) assert isinstance(gasoil, GasOil) assert gasoil.sgcr == 0.05 @@ -409,7 +441,7 @@ def test_factory_gasoil(): assert "Zero capillary pressure" in sgof gasoil = pyscal_factory.create_gas_oil( - dict(ng=1.2, nog=2, krgend=0.8, krgmax=0.9, kroend=0.6) + {"ng": 1.2, "nog": 2, "krgend": 0.8, "krgmax": 0.9, "kroend": 0.6} ) sgof = gasoil.SGOF() sat_table_str_ok(sgof) @@ -417,14 +449,16 @@ def test_factory_gasoil(): assert "krgend=0.8" in sgof check_table(gasoil.table) - gasoil = pyscal_factory.create_gas_oil(dict(ng=1.3, Log=2, Eog=2, Tog=2)) + gasoil = pyscal_factory.create_gas_oil({"ng": 1.3, "Log": 2, "Eog": 2, "Tog": 2}) sgof = gasoil.SGOF() check_table(gasoil.table) sat_table_str_ok(sgof) assert "Corey krg" in sgof assert "LET krog" in sgof - gasoil = pyscal_factory.create_gas_oil(dict(Lg=1, Eg=1, Tg=1, Log=2, Eog=2, Tog=2)) + gasoil = pyscal_factory.create_gas_oil( + {"Lg": 1, "Eg": 1, "Tg": 1, "Log": 2, "Eog": 2, "Tog": 2} + ) sgof = gasoil.SGOF() sat_table_str_ok(sgof) check_table(gasoil.table) @@ -438,18 +472,18 @@ def test_factory_wog_gascondensate(): in sgrw=sorw for the underlying WaterOil object, and also there are additional parameters sgro and kromax for GasOil.""" wcg = PyscalFactory.create_water_oil_gas( - dict( - nw=2, - now=3, - ng=1, - nog=2, - sgrw=0.1, - swl=0.1, - sgcr=0.1, - sgro=0.1, - kroend=0.5, - kromax=0.9, - ) + { + "nw": 2, + "now": 3, + "ng": 1, + "nog": 2, + "sgrw": 0.1, + "swl": 0.1, + "sgcr": 0.1, + "sgro": 0.1, + "kroend": 0.5, + "kromax": 0.9, + } ) assert wcg.gasoil.sgro == 0.1 assert wcg.wateroil.sorw == 0.1 @@ -470,29 +504,29 @@ def test_factory_wog_gascondensate(): # Different sorw and sgrw is a hard error: with pytest.raises(ValueError, match="must equal"): PyscalFactory.create_water_oil_gas( - dict(nw=2, now=3, ng=1, nog=2, sorw=0.2, sgrw=0.1, swl=0.1) + {"nw": 2, "now": 3, "ng": 1, "nog": 2, "sorw": 0.2, "sgrw": 0.1, "swl": 0.1} ) # But it will pass if they both are supplied but are equal: wcg_2 = PyscalFactory.create_water_oil_gas( - dict(nw=2, now=3, ng=1, nog=2, sorw=0.2, sgrw=0.2, swl=0.1) + {"nw": 2, "now": 3, "ng": 1, "nog": 2, "sorw": 0.2, "sgrw": 0.2, "swl": 0.1} ) assert "sorw=0.2" in wcg_2.SWOF() # kroend higher than kromax is an error: with pytest.raises(AssertionError): PyscalFactory.create_water_oil_gas( - dict( - nw=2, - now=3, - ng=1, - nog=2, - sgcr=0.1, - sgro=0.1, - kromax=0.5, - kroend=0.8, - swl=0.1, - ) + { + "nw": 2, + "now": 3, + "ng": 1, + "nog": 2, + "sgcr": 0.1, + "sgro": 0.1, + "kromax": 0.5, + "kroend": 0.8, + "swl": 0.1, + } ) @@ -500,7 +534,15 @@ def test_factory_go_gascondensate(): """In gas condensate problems, the sgro and kromax parameters are relevant""" pyscal_factory = PyscalFactory() gasoil = pyscal_factory.create_gas_oil( - dict(sgro=0.1, sgcr=0.1, tag="Good sand", ng=1, nog=2, kroend=0.5, kromax=0.9) + { + "sgro": 0.1, + "sgcr": 0.1, + "tag": "Good sand", + "ng": 1, + "nog": 2, + "kroend": 0.5, + "kromax": 0.9, + } ) assert isinstance(gasoil, GasOil) assert gasoil.sgro == 0.1 @@ -523,16 +565,22 @@ def test_factory_gaswater(): pyscal_factory.create_gas_water() with pytest.raises(TypeError): - # pylint: disable=unexpected-keyword-arg - pyscal_factory.create_gas_water(swirr=0.01) # noqa + pyscal_factory.create_gas_water(swirr=0.01) with pytest.raises(TypeError): # (it must be a dictionary) - # pylint: disable=unexpected-keyword-arg pyscal_factory.create_gas_water(params="swirr 0.01") gaswater = pyscal_factory.create_gas_water( - dict(swirr=0.01, swl=0.03, sgrw=0.1, sgcr=0.15, tag="gassy sand", ng=2, nw=2) + { + "swirr": 0.01, + "swl": 0.03, + "sgrw": 0.1, + "sgcr": 0.15, + "tag": "gassy sand", + "ng": 2, + "nw": 2, + } ) assert isinstance(gaswater, GasWater) @@ -559,7 +607,7 @@ def test_factory_gaswater(): assert "ng=2" in sgfn assert "gassy sand" in sgfn - gaswater = pyscal_factory.create_gas_water(dict(lg=1, eg=1, tg=1, nw=3)) + gaswater = pyscal_factory.create_gas_water({"lg": 1, "eg": 1, "tg": 1, "nw": 3}) sgfn = gaswater.SGFN() swfn = gaswater.SWFN() @@ -579,13 +627,12 @@ def test_factory_wateroilgas(): with pytest.raises(TypeError): # (this must be a dictionary) - # pylint: disable=unexpected-keyword-arg - pyscal_factory.create_water_oil_gas(swirr=0.01) # noqa + pyscal_factory.create_water_oil_gas(swirr=0.01) with pytest.raises(TypeError): pyscal_factory.create_water_oil_gas(params="swirr 0.01") - wog = pyscal_factory.create_water_oil_gas(dict(nw=2, now=3, ng=1, nog=2.5)) + wog = pyscal_factory.create_water_oil_gas({"nw": 2, "now": 3, "ng": 1, "nog": 2.5}) swof = wog.SWOF() sgof = wog.SGOF() sat_table_str_ok(swof) # sgof code works for swof also currently @@ -598,7 +645,7 @@ def test_factory_wateroilgas(): check_table(wog.wateroil.table) # Some users will mess up lower vs upper case: - wog = pyscal_factory.create_water_oil_gas(dict(NW=2, NOW=3, NG=1, nog=2.5)) + wog = pyscal_factory.create_water_oil_gas({"NW": 2, "NOW": 3, "NG": 1, "nog": 2.5}) swof = wog.SWOF() sgof = wog.SGOF() sat_table_str_ok(swof) # sgof code works for swof also currently @@ -609,7 +656,7 @@ def test_factory_wateroilgas(): assert "Corey krow" in swof # Mangling data - wateroil = pyscal_factory.create_water_oil_gas(dict(nw=2, now=3, ng=1)) + wateroil = pyscal_factory.create_water_oil_gas({"nw": 2, "now": 3, "ng": 1}) assert wateroil.gasoil is None @@ -617,7 +664,7 @@ def test_factory_wateroilgas_deprecated_krowgend(): """Using long-time deprecated krowend and krogend will fail""" with pytest.raises(ValueError): PyscalFactory.create_water_oil_gas( - dict(nw=2, now=3, ng=1, nog=2.5, krowend=0.6, krogend=0.7) + {"nw": 2, "now": 3, "ng": 1, "nog": 2.5, "krowend": 0.6, "krogend": 0.7} ) @@ -625,7 +672,7 @@ def test_factory_wateroilgas_wo(): """Test making only wateroil through the wateroilgas factory""" pyscal_factory = PyscalFactory() wog = pyscal_factory.create_water_oil_gas( - dict(nw=2, now=3, kroend=0.5, sorw=0.04, swcr=0.1) + {"nw": 2, "now": 3, "kroend": 0.5, "sorw": 0.04, "swcr": 0.1} ) swof = wog.SWOF() assert "Corey krw" in swof @@ -642,7 +689,14 @@ def test_factory_wateroil_paleooil(caplog): pyscal_factory = PyscalFactory() sorw = 0.09 wateroil = pyscal_factory.create_water_oil( - dict(nw=2, now=3, kroend=0.5, sorw=sorw, socr=sorw + 0.01, swcr=0.1) + { + "nw": 2, + "now": 3, + "kroend": 0.5, + "sorw": sorw, + "socr": sorw + 0.01, + "swcr": 0.1, + } ) swof = wateroil.SWOF() assert "Corey krw" in swof @@ -653,7 +707,7 @@ def test_factory_wateroil_paleooil(caplog): # If socr is close to sorw, socr is reset to sorw. for socr in [sorw - 1e-9, sorw, sorw + 1e-9]: wo_socrignored = pyscal_factory.create_water_oil( - dict(nw=2, now=3, kroend=0.5, sorw=0.09, socr=socr, swcr=0.1) + {"nw": 2, "now": 3, "kroend": 0.5, "sorw": 0.09, "socr": socr, "swcr": 0.1} ) swof = wo_socrignored.SWOF() assert "socr" not in swof # socr is effectively ignored when = sorw. @@ -665,7 +719,15 @@ def test_factory_wateroil_paleooil(caplog): with pytest.raises(ValueError, match="socr must be equal to or larger than sorw"): pyscal_factory.create_water_oil( - dict(nw=2, now=3, kroend=0.5, sorw=0.09, socr=0.001, swcr=0.1, h=0.1) + { + "nw": 2, + "now": 3, + "kroend": 0.5, + "sorw": 0.09, + "socr": 0.001, + "swcr": 0.1, + "h": 0.1, + } ) @@ -700,7 +762,7 @@ def test_load_relperm_df(tmp_path, caplog): assert "Sheet name only relevant for XLSX files, ignoring foo" in caplog.text with pytest.raises(ValueError, match="Unsupported argument"): - PyscalFactory.load_relperm_df(dict(foo=1)) + PyscalFactory.load_relperm_df({"foo": 1}) # Perturb the dataframe, this should trigger errors with pytest.raises(ValueError): @@ -1018,21 +1080,21 @@ def test_check_deprecated_krowgend(): After pyscal 0.8 presence of krogend and krowend is a ValueError """ with pytest.raises(ValueError): - PyscalFactory.create_water_oil(dict(swl=0.1, nw=2, now=2, krowend=0.4)) + PyscalFactory.create_water_oil({"swl": 0.1, "nw": 2, "now": 2, "krowend": 0.4}) with pytest.raises(ValueError): - PyscalFactory.create_gas_oil(dict(swl=0.1, ng=2, nog=2, krogend=0.4)) + PyscalFactory.create_gas_oil({"swl": 0.1, "ng": 2, "nog": 2, "krogend": 0.4}) # If krogend and kroend are both present, krogend is to be silently ignored # (random columns are in general accepted and ignored by pyscal) gasoil = PyscalFactory.create_gas_oil( - dict(swl=0.1, ng=2, nog=2, krogend=0.4, kroend=0.3) + {"swl": 0.1, "ng": 2, "nog": 2, "krogend": 0.4, "kroend": 0.3} ) assert gasoil.table["KROG"].max() == 0.3 wateroil = PyscalFactory.create_water_oil( - dict(swl=0.1, nw=2, now=2, krowend=0.4, kroend=0.3) + {"swl": 0.1, "nw": 2, "now": 2, "krowend": 0.4, "kroend": 0.3} ) assert wateroil.table["KROW"].max() == 0.3 @@ -1159,19 +1221,21 @@ def test_sufficient_params_gaswater(): for gas-water only""" assert factory.sufficient_gas_water_params({"nw": 0, "ng": 0}) assert not factory.sufficient_gas_water_params({"nw": 0, "nog": 0}) - assert factory.sufficient_gas_water_params(dict(lw=0, ew=0, tw=0, lg=0, eg=0, tg=0)) - assert not factory.sufficient_gas_water_params(dict(lw=0)) - assert not factory.sufficient_gas_water_params(dict(lw=0, lg=0)) - assert not factory.sufficient_gas_water_params(dict(lw=0, lg=0)) + assert factory.sufficient_gas_water_params( + {"lw": 0, "ew": 0, "tw": 0, "lg": 0, "eg": 0, "tg": 0} + ) + assert not factory.sufficient_gas_water_params({"lw": 0}) + assert not factory.sufficient_gas_water_params({"lw": 0, "lg": 0}) + assert not factory.sufficient_gas_water_params({"lw": 0, "lg": 0}) with pytest.raises(ValueError): - factory.sufficient_gas_water_params(dict(lw=0), failhard=True) + factory.sufficient_gas_water_params({"lw": 0}, failhard=True) with pytest.raises(ValueError): factory.sufficient_gas_water_params({"nw": 3}, failhard=True) - assert factory.sufficient_gas_water_params(dict(lw=0, ew=0, tw=0, ng=0)) - assert factory.sufficient_gas_water_params(dict(lg=0, eg=0, tg=0, nw=0)) - assert not factory.sufficient_gas_water_params(dict(lg=0, eg=0, tg=0, ng=0)) + assert factory.sufficient_gas_water_params({"lw": 0, "ew": 0, "tw": 0, "ng": 0}) + assert factory.sufficient_gas_water_params({"lg": 0, "eg": 0, "tg": 0, "nw": 0}) + assert not factory.sufficient_gas_water_params({"lg": 0, "eg": 0, "tg": 0, "ng": 0}) def test_case_aliasing(): diff --git a/tests/test_fromtable.py b/tests/test_fromtable.py index 5ee342bd..b9b3f8b7 100644 --- a/tests/test_fromtable.py +++ b/tests/test_fromtable.py @@ -627,7 +627,7 @@ def test_fromtable_types(): # But this should not make sense. df2 = pd.DataFrame( columns=["SW", "KRW", "KROW", "PC"], - data=[["0", dict(foo="bar"), "1", "2"], ["1", "1", "0", "0"]], + data=[["0", {"foo": "bar"}, "1", "2"], ["1", "1", "0", "0"]], ) wateroil = WaterOil(h=0.1) with pytest.raises((ValueError, TypeError)): diff --git a/tests/test_gasoil.py b/tests/test_gasoil.py index 2cdf875f..bbf9130b 100644 --- a/tests/test_gasoil.py +++ b/tests/test_gasoil.py @@ -198,10 +198,7 @@ def test_gasoil_krendmax( swl, sgcr, sorg, sgrononzero, kroend, kromax, krgend, krgmax, h, fast ): """Test that relperm curves are valid in all numerical corner cases.""" - if sgrononzero: - sgro = sgcr - else: - sgro = 0 + sgro = sgcr if sgrononzero else 0 try: assert 1 - sorg - swl - sgcr > 1 / SWINTEGERS, "No saturation range left" gasoil = GasOil( @@ -369,7 +366,6 @@ def test_nexus(): sep=r"\s+", header=None, ) - # pylint: disable=no-member # false positive on Pandas dataframe assert (df.values <= 1.0).all() assert (df.values >= 0.0).all() @@ -606,5 +602,5 @@ def test_selfcheck(columnname, errorvalues): gasoil.table[columnname] = errorvalues assert not gasoil.selfcheck() assert gasoil.SGOF() == "" - if not columnname == "KROG": + if columnname != "KROG": assert gasoil.SGFN() == "" diff --git a/tests/test_gaswater.py b/tests/test_gaswater.py index e939c51b..902be7bb 100644 --- a/tests/test_gaswater.py +++ b/tests/test_gaswater.py @@ -61,7 +61,6 @@ def test_constructor(): gaswater.wateroil.tag = "Foo" gaswater.gasoil.tag = "Bar" with pytest.raises(ValueError, match="Internal tag-inconsistency in GasWater"): - # pylint: disable=pointless-statement gaswater.tag # Trigger self-check bug warning: diff --git a/tests/test_interactive_plots.py b/tests/test_interactive_plots.py index 42e37cbf..e0785623 100644 --- a/tests/test_interactive_plots.py +++ b/tests/test_interactive_plots.py @@ -176,14 +176,8 @@ def test_interpolate_go(): kromax_h = random.uniform(0.5, 1) kroend_l = min(random.uniform(0.5, 1), kromax_l) kroend_h = min(random.uniform(0.5, 1), kromax_h) - if random.uniform(0, 1) > 0.5: - krgendanchor_l = "sorg" - else: - krgendanchor_l = "" - if random.uniform(0, 1) > 0.5: - krgendanchor_h = "sorg" - else: - krgendanchor_h = "" + krgendanchor_l = "sorg" if random.uniform(0, 1) > 0.5 else "" + krgendanchor_h = "sorg" if random.uniform(0, 1) > 0.5 else "" go_low = GasOil( swl=swl_l, sgcr=sgcr_l, @@ -243,7 +237,6 @@ def test_interpolate_go(): @pytest.mark.parametrize("", [(), (), ()]) # 3 repeated runs def test_interpolate_gw(): """Discrete test scenarios for gaswater interpolation""" - # pylint: disable=too-many-locals swl_l = random.uniform(0, 0.1) swcr_l = swl_l + random.uniform(0, 0.1) sgrw_l = random.uniform(0, 0.2) @@ -310,7 +303,6 @@ def test_interpolate_gw(): @pytest.mark.plot def test_SCAL_interpolation(): """Demonstration of interpolation between LET curves, 2x2 subplot""" - # pylint: disable=invalid-name matplotlib.style.use("ggplot") rec = PyscalFactory.create_scal_recommendation( diff --git a/tests/test_pyscalcli.py b/tests/test_pyscalcli.py index 543aea78..aeb2eea5 100644 --- a/tests/test_pyscalcli.py +++ b/tests/test_pyscalcli.py @@ -28,9 +28,7 @@ def test_log_levels(tmp_path, verbosity_flag): relperm_file = str( # A cell in this xlsx contains "Åre 1.5", does not work on Windows - Path(__file__).absolute().parent - / "data" - / "relperm-input-example.xlsx" + Path(__file__).absolute().parent / "data" / "relperm-input-example.xlsx" ) commands = ["pyscal", relperm_file] @@ -58,7 +56,6 @@ def test_log_levels(tmp_path, verbosity_flag): def test_pyscal_client_static(tmp_path, caplog, default_loglevel, mocker): - # pylint: disable=unused-argument # default_loglevel fixture is in conftest.py """Test pyscal client for static relperm input""" testdir = Path(__file__).absolute().parent @@ -437,8 +434,6 @@ def test_pyscalcli_gaswater_scal(tmp_path, caplog, mocker): def test_pyscal_client_scal(tmp_path, caplog, default_loglevel, mocker): - # pylint: disable=unused-argument - # default_loglevel fixture is in conftest.py """Test the command line endpoint on SCAL recommendation""" scalrec_file = Path(__file__).absolute().parent / "data/scal-pc-input-example.xlsx" diff --git a/tests/test_pyscallist.py b/tests/test_pyscallist.py index 803e59da..b4f2fe0e 100644 --- a/tests/test_pyscallist.py +++ b/tests/test_pyscallist.py @@ -45,10 +45,8 @@ def test_pyscallist_basic(): assert len(p_list) == 1 assert isinstance(p_list[1], WaterOil) with pytest.raises(IndexError): - # pylint: disable=W0104 p_list[0] with pytest.raises(IndexError): - # pylint: disable=W0104 p_list[2] with pytest.raises(ValueError): p_list.append(GasOil()) @@ -158,7 +156,7 @@ def test_df(): assert "SATNUM" in dframe assert dframe["SATNUM"].min() == 1 assert len(dframe["SATNUM"].unique()) == len(scalrec_list) - assert set(dframe["CASE"]) == set(["pess", "base", "opt"]) + assert set(dframe["CASE"]) == {"pess", "base", "opt"} assert dframe["SATNUM"].max() == len(scalrec_list) if HAVE_ECL2DF: # Test using ecl2df to do the include file printing. First we need to @@ -779,7 +777,7 @@ def test_error_messages_pr_satnum(): ], ) # Perturb all entries in the dataframe: - for rowidx in list(range(0, 6)): + for rowidx in list(range(6)): for colidx in list(range(2, 6)): dframe_perturbed = dframe.copy() dframe_perturbed.iloc[rowidx, colidx] = np.nan diff --git a/tests/test_slgof.py b/tests/test_slgof.py index d25b5466..3b7e3b85 100644 --- a/tests/test_slgof.py +++ b/tests/test_slgof.py @@ -54,7 +54,7 @@ def test_slgof(swl, sorg, sgcr): assert np.isclose(slgof["KROG"].values[0], 0) # If we ruin the object, SLGOF() will return an empty string: - wog.gasoil.table.drop("KRG", axis="columns", inplace=True) + wog.gasoil.table = wog.gasoil.table.drop("KRG", axis="columns") assert wog.gasoil.SLGOF() == "" assert wog.SLGOF() == "" diff --git a/tests/test_utils_capillarypressure.py b/tests/test_utils_capillarypressure.py index 8080dd26..17684d61 100644 --- a/tests/test_utils_capillarypressure.py +++ b/tests/test_utils_capillarypressure.py @@ -11,8 +11,6 @@ PASCAL = 1e-05 # One pascal in bar. -# pylint: disable=protected-access # Private functions should be tested too - @pytest.mark.parametrize( "sw, a, b, poro_ref, perm_ref, drho, g, expected", @@ -38,7 +36,6 @@ ) def test_simple_J(sw, a, b, poro_ref, perm_ref, drho, g, expected): """Test the simple J formula implementation""" - # pylint: disable=invalid-name,too-many-arguments result = capillarypressure.simple_J(sw, a, b, poro_ref, perm_ref, drho, g) if isinstance(result, (list, np.ndarray)): @@ -56,7 +53,6 @@ def test_simple_J(sw, a, b, poro_ref, perm_ref, drho, g, expected): ) def test_swl_from_height_simple_J(swlheight, swirr, a, b, poro_ref, perm_ref, expected): """Test the calculation of swlheight from input parameters""" - # pylint: disable=invalid-name,too-many-arguments result = capillarypressure.swl_from_height_simpleJ( swlheight, swirr, a, b, poro_ref, perm_ref ) @@ -76,7 +72,6 @@ def test_swl_from_height_simple_J(swlheight, swirr, a, b, poro_ref, perm_ref, ex def test_inverses_sw_simpleJ(j_value, a, b): """Ensure that the pair of functions going from sw to J and back are truly inverses of each other""" - # pylint: disable=invalid-name # simpleJ sw = capillarypressure._simpleJ_to_sw(j_value, a, b) assert np.isclose(capillarypressure._sw_to_simpleJ(sw, a, b), j_value) @@ -88,7 +83,6 @@ def test_inverses_sw_simpleJ(j_value, a, b): ) def test_inverses_simpleJ_sw(sw_value, a, b): """Inverse of the test function above""" - # pylint: disable=invalid-name # simpleJ result = capillarypressure._simpleJ_to_sw( capillarypressure._sw_to_simpleJ(sw_value, a, b), a, b ) @@ -102,7 +96,6 @@ def test_inverses_simpleJ_sw(sw_value, a, b): ) def test_inverses_simpleJ_height(J, poro_ref, perm_ref): """Test round-trip calculation of J-value from height""" - # pylint: disable=invalid-name result = capillarypressure._height_to_simpleJ( capillarypressure._simpleJ_to_height(J, poro_ref, perm_ref), poro_ref, perm_ref ) @@ -116,7 +109,6 @@ def test_inverses_simpleJ_height(J, poro_ref, perm_ref): ) def test_inverses_height_simpleJ(height, poro_ref, perm_ref): """Test round-trip calculation of height-value from J""" - # pylint: disable=invalid-name result = capillarypressure._simpleJ_to_height( capillarypressure._height_to_simpleJ(height, poro_ref, perm_ref), poro_ref, diff --git a/tests/test_utils_interpolation.py b/tests/test_utils_interpolation.py index da44e644..328b24a6 100644 --- a/tests/test_utils_interpolation.py +++ b/tests/test_utils_interpolation.py @@ -55,7 +55,6 @@ def test_normalize_nonlinpart_wo_hypo( now2, kroend2, ): - # pylint: disable=too-many-arguments,too-many-locals """Test the normalization code in utils. In particular the fill_value argument to scipy has been tuned to @@ -275,7 +274,6 @@ def test_interpolate_wo( kroend_l, kroend_h, ): - # pylint: disable=too-many-arguments,too-many-locals """ Generate two random WaterOil curves, interpolate between them and check that the difference between each interpolant is small, @@ -361,7 +359,6 @@ def test_interpolate_wo_pc(swl, dswcr, dswlhigh, sorw, a_l, a_h, b_l, b_h): this essentially checks that we can go continously between the two functions. """ - # pylint: disable=too-many-locals wo_low = WaterOil(swl=swl, swcr=swl + dswcr, sorw=sorw) wo_high = WaterOil( swl=swl + dswlhigh, swcr=swl + dswlhigh + dswcr, sorw=max(sorw - 0.01, 0) @@ -453,7 +450,6 @@ def test_normalize_nonlinpart_go_hypo( kroend2, kromax2, ): - # pylint: disable=too-many-arguments,too-many-locals """Test the normalization code in utils. In particular the fill_value argument to scipy has been tuned to @@ -709,7 +705,6 @@ def test_interpolate_go( kroend_l, kroend_h, ): - # pylint: disable=too-many-arguments,too-many-locals """Test many possible combinations of interpolation between two Corey gasoil curves, looking for numerical corner cases""" h = 0.01 diff --git a/tests/test_wateroil.py b/tests/test_wateroil.py index 0dffd7b8..1a748d12 100644 --- a/tests/test_wateroil.py +++ b/tests/test_wateroil.py @@ -296,7 +296,6 @@ def test_nexus(): sep=r"\s+", header=None, ) - # pylint: disable=no-member # false positive on Pandas dataframe assert (df.values <= 1.0).all() assert (df.values >= 0.0).all() @@ -327,5 +326,5 @@ def test_selfcheck(columnname, errorvalues): wateroil.table[columnname] = errorvalues assert not wateroil.selfcheck() assert wateroil.SWOF() == "" - if not columnname == "KROW": + if columnname != "KROW": assert wateroil.SWFN() == "" diff --git a/tests/test_wateroil_saturation.py b/tests/test_wateroil_saturation.py index 335f760d..a8bf2180 100644 --- a/tests/test_wateroil_saturation.py +++ b/tests/test_wateroil_saturation.py @@ -1,5 +1,7 @@ """Test module for the saturation ranges in WaterOil objects""" +import contextlib + import hypothesis.strategies as st from hypothesis import given @@ -20,10 +22,8 @@ def test_wateroil_random(swirr, swl, swcr, sorw, socr, h, tag): """Shoot wildly with arguments, the code should throw ValueError or AssertionError when input is invalid, but we don't want other crashes""" - try: + with contextlib.suppress(ValueError, AssertionError): WaterOil(swirr=swirr, swl=swl, swcr=swcr, sorw=sorw, socr=socr, h=h, tag=tag) - except (ValueError, AssertionError): - pass @given( diff --git a/tests/test_wateroilgas.py b/tests/test_wateroilgas.py index 726eede1..16c30d21 100644 --- a/tests/test_wateroilgas.py +++ b/tests/test_wateroilgas.py @@ -77,7 +77,6 @@ def test_manipulated_attributes_none(): """It is allowed to manipulate the WaterOilGas by setting the wateroil and/or the gasoil attributes to None, this is performed in SCALrecommendation.interpolate() for example. Test this behaviour.""" - # pylint: disable=pointless-statement # The pointless statements trigger errors wog_go = WaterOilGas(tag="gasoilonly") # Make it into a two-phase object: