Skip to content

Commit

Permalink
Merge pull request #20 from ocefpaf/pre-commit
Browse files Browse the repository at this point in the history
Add pre-commit
  • Loading branch information
ocefpaf authored Oct 19, 2022
2 parents 9e6f0d9 + 23503cd commit a27a598
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 19 deletions.
83 changes: 83 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: check-ast
- id: debug-statements
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-added-large-files
- id: requirements-txt-fixer
- id: file-contents-sorter
files: requirements-dev.txt

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
exclude: docs/source/conf.py
args: [--max-line-length=105]

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
additional_dependencies: [toml]
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/keewis/blackdoc
rev: v0.3.7
hooks:
- id: blackdoc

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
exclude: >
(?x)^(
.*\.yaml
)$
args:
- --quiet-level=2

- repo: https://github.com/asottile/pyupgrade
rev: v3.1.0
hooks:
- id: pyupgrade
args:
- --py36-plus

- repo: https://github.com/dosisod/refurb
rev: v1.4.0
hooks:
- id: refurb

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.3.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
exclude: ^(docs|setup.py|ciso/tests)

ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
autofix_prs: false
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: monthly
skip: []
submodules: false
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Redistribution and use in source and binary forms, with or without modification,

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions ciso/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Cythonized ISOsurface calculation (CISO)."""

from ciso.ciso import zslice

__all__ = ["zslice"]
Expand Down
20 changes: 10 additions & 10 deletions ciso/ciso.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Compute iso-surface slices on 3D fields."""

import numpy as np

from ciso._ciso import _zslice


def zslice(q, p, p0):
"""
Returns a 2D slice of the variable `q` from a 3D field defined by `p`,
along an iso-surface at `p0` using a linear interpolation.
Return a 2D slice of the variable `q` from a 3D field defined by `p`.
The slice is defined along an iso-surface at `p0` using a linear interpolation.
The result `q_iso` is a projection of variable at property == iso-value
in the first non-singleton dimension.
Expand All @@ -24,16 +26,15 @@ def zslice(q, p, p0):
"""
if q.shape != p.shape:
msg = "Arrays q {} and p {} must be of the same shape.".format
raise ValueError(msg(q.shape, p.shape))
raise ValueError(
f"Arrays q {q.shape} and p {p.shape} must be of the same shape.",
)

if np.array(p0).squeeze().ndim != 0:
msg = "p0 must be a float number or 0-dim array. Got {!r}.".format
raise ValueError(msg(p0))
raise ValueError(f"p0 must be a float number or 0-dim array. Got {p0!r}.")

if p0 < p.min() or p.max() < p0:
msg = "p0 {} is outise p bounds ({}, {}).".format
raise ValueError(msg(p0, p.min(), p.max()))
raise ValueError(f"p0 {p0} is outside p bounds ({p.min}, {p.max}).")

q = np.asfarray(q)
p = np.asfarray(p)
Expand All @@ -45,5 +46,4 @@ def zslice(q, p, p0):
elif q.ndim == 2:
return _zslice(q, p, p0)
else:
msg = "Expected 2D (UGRID) or 3D (S/RGRID) arrays. Got {}D.".format
raise ValueError(msg(q.ndim))
raise ValueError(f"Expected 2D (UGRID) or 3D (S/RGRID) arrays. Got {q.ndim}D.")
10 changes: 6 additions & 4 deletions ciso/tests/test_ciso.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import, division, print_function

import os
import sys

import numpy as np
import pytest

Expand Down Expand Up @@ -39,13 +38,16 @@ def test_bad_dtypes(data):
zslice(np.empty_like(data["q"], dtype=np.str_), data["p"], p0=0)


@pytest.mark.parametrize("dtype", [int, float, np.int32, np.int64, np.float16, np.float32, np.float64])
@pytest.mark.parametrize(
"dtype",
[int, float, np.int32, np.int64, np.float16, np.float32, np.float64],
)
def test_good_dtypes(data, dtype):
zslice(np.empty_like(data["q"], dtype=dtype), data["p"], p0=0)


@pytest.mark.skipif(
sys.platform in ["win32"],
sys.platform == "win32",
reason="Windows doesn't provide float128",
)
def test_good_dtypes_float128(data):
Expand Down
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
from Cython.Build import cythonize
from setuptools import Extension, setup


extensions = [
Extension(
"ciso._ciso", ["ciso/_ciso.pyx"], include_dirs=[numpy.get_include()]
)
Extension("ciso._ciso", ["ciso/_ciso.pyx"], include_dirs=[numpy.get_include()]),
]

setup(
Expand Down

0 comments on commit a27a598

Please sign in to comment.