From d9ebd7e727595cabbc8e949584396a42b14a90d5 Mon Sep 17 00:00:00 2001 From: Constantine Evans Date: Tue, 1 Aug 2023 13:20:25 +0100 Subject: [PATCH] Build and lint updates - Use ruff, move configuration for some things to pyproject.toml. - Update namespace configuration. - Deprecate py36 support, add tests for py310, py311. - Add numba tests for py310, py311. - Update pre-commit, add ruff. --- .coveragerc | 3 +-- .github/workflows/python-package.yml | 4 ++-- .gitignore | 4 ++++ .pre-commit-config.yaml | 4 ++-- pyproject.toml | 15 +++++++++++++++ requirements.txt | 1 - src/scikits/__init__.py | 1 - src/scikits/bootstrap/bootstrap.py | 18 ++++++++---------- tests/bootstrap_test.py | 4 ++-- tox.ini | 10 +++++----- 10 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 pyproject.toml delete mode 100644 src/scikits/__init__.py diff --git a/.coveragerc b/.coveragerc index 57961b5..d55de99 100644 --- a/.coveragerc +++ b/.coveragerc @@ -13,8 +13,7 @@ source = [report] show_missing = true precision = 2 -exclude_lines = +exclude_lines = pragma: no cover @overload @njit - diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 406c481..0ed7f7c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -13,14 +13,14 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: [3.6, 3.7, 3.8, 3.9, "3.10", pypy3] + python-version: [3.7, 3.8, 3.9, "3.10", "3.11", pypy3] optionals: [none, pandas, numba] exclude: - python-version: pypy3 optionals: pandas - python-version: pypy3 optionals: numba - - python-version: "3.10" + - python-version: "3.11" optionals: numba - os: macos-latest python-version: pypy3 diff --git a/.gitignore b/.gitignore index 75666e2..1af7182 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,10 @@ develop-eggs # Installer logs pip-log.txt + +*~ +\#*\# + # Unit test / coverage reports .coverage .tox diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 707053e..df6e8c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -15,6 +15,6 @@ repos: - id: ruff args: [ --fix, --exit-non-zero-on-fix ] - repo: https://github.com/psf/black - rev: 21.5b2 + rev: 23.7.0 hooks: - id: black diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7878dec --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[build-system] +requires = ["setuptools>=56", "setuptools_scm[toml]>=3.4.1"] +build-backend = "setuptools.build_meta" + +[tool.ruff] +line-length = 120 +ignore = ["F405", "F403"] + +[tool.mypy] +ignore_missing_imports = true +warn_unused_configs = true +warn_return_any = true + +[tool.black] +line-length = 88 diff --git a/requirements.txt b/requirements.txt index 9bedae6..b4cdf2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ numpy pyerf typing_extensions>=4.1 - diff --git a/src/scikits/__init__.py b/src/scikits/__init__.py deleted file mode 100644 index 5284146..0000000 --- a/src/scikits/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__("pkg_resources").declare_namespace(__name__) diff --git a/src/scikits/bootstrap/bootstrap.py b/src/scikits/bootstrap/bootstrap.py index ca711e8..f89636d 100644 --- a/src/scikits/bootstrap/bootstrap.py +++ b/src/scikits/bootstrap/bootstrap.py @@ -2,7 +2,7 @@ It also provides an algorithm which estimates the probability that the statistics lies satisfies some criteria, e.g. lies in some interval.""" -from __future__ import absolute_import, division, print_function +from __future__ import absolute_import, division, print_function, annotations from math import ceil, sqrt from typing import Sequence, cast, overload @@ -454,9 +454,7 @@ def ci( if nvals.ndim == 1: out = np.abs(statfunction(*tdata) - stat[nvals])[np.newaxis].T # type: ignore else: - out = np.abs( - statfunction(*tdata) - stat[(nvals, np.indices(nvals.shape)[1:])] # type: ignore - ).T.squeeze() + out = np.abs(statfunction(*tdata) - stat[(nvals, np.indices(nvals.shape)[1:])]).T.squeeze() # type: ignore else: raise ValueError("Output option {0} is not supported.".format(output)) @@ -498,17 +496,17 @@ def _ci_abc( (statfunction(*tdata, weights=p0 - ep * di) for di in di_full), dtype=float ) t1 = (tp - tm) / (2 * ep) - t2 = (tp - 2 * t0 + tm) / ep ** 2 + t2 = (tp - 2 * t0 + tm) / ep**2 - sighat = np.sqrt(np.sum(t1 ** 2)) / n - a = (np.sum(t1 ** 3)) / (6 * n ** 3 * sighat ** 3) - delta = t1 / (n ** 2 * sighat) + sighat = np.sqrt(np.sum(t1**2)) / n + a = (np.sum(t1**3)) / (6 * n**3 * sighat**3) + delta = t1 / (n**2 * sighat) cq = ( statfunction(*tdata, weights=p0 + ep * delta) - 2 * t0 + statfunction(*tdata, weights=p0 - ep * delta) - ) / (2 * sighat * ep ** 2) - bhat = np.sum(t2) / (2 * n ** 2) + ) / (2 * sighat * ep**2) + bhat = np.sum(t2) / (2 * n**2) curv = bhat / sighat - cq z0 = nppf(2 * ncdf(a) * ncdf(-curv)) Z = z0 + nppf(alphas) diff --git a/tests/bootstrap_test.py b/tests/bootstrap_test.py index 1356c72..a44cde7 100644 --- a/tests/bootstrap_test.py +++ b/tests/bootstrap_test.py @@ -16,7 +16,7 @@ class TestCI: - def setup(self) -> None: + def setup_method(self) -> None: self.data = np.array( [ 1.34016346, @@ -124,7 +124,7 @@ def test_subsample_indices_fixed(self) -> None: def test_subsample_size_too_large(self) -> None: with pytest.raises(ValueError): - indices = boot.subsample_indices(self.data, 1000, 30) + boot.subsample_indices(self.data, 1000, 30) def test_subsample_indices_notsame(self) -> None: indices = boot.subsample_indices(np.arange(0, 50), 1000, -1) diff --git a/tox.ini b/tox.ini index bb7ab58..cd30754 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,12 @@ [tox] -envlist = {py36,py37,py38,py39}-{pandas,none,numba,pandas-numba},pypy3,black,mypy,report +envlist = {py37,py38,py39,py310,py311}-{pandas,none,numba,pandas-numba},pypy3,black,mypy,report [tool:pytest] testpath = tests [testenv] setenv = - py{,36,37,38,39}-{pandas,none,numba},pypy3: COVERAGE_FILE = .coverage.{envname} + py{37,38,39,310,311}-{pandas,none,numba},pypy3: COVERAGE_FILE = .coverage.{envname} commands = pytest --cov --cov-report=xml --cov-report=term-missing {posargs:-vv} deps = @@ -17,9 +17,9 @@ deps = !pypy3-pandas: pandas !pypy3-numba: numba depends = - {,py36,py37,py38,py39}-{pandas,none,numba,pandas-numba},pypy3: clean - codecov: {,py36,py37,py38,py39}-{pandas,none,numba,pandas-numba},pypy3 - report: {,py36,py37,py38,py39}-{pandas,none,numba,pandas-numba},pypy3 + {py37,py38,py39,py311}-{pandas,none,numba,pandas-numba},pypy3: clean + codecov: {py37,py38,py39,py311}-{pandas,none,numba,pandas-numba},pypy3 + report: {py37,py38,py39,py311}-{pandas,none,numba,pandas-numba},pypy3 [testenv:black] description = run black with check-only under {basepython}