Skip to content

Commit

Permalink
Package health (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronspring committed Oct 30, 2023
1 parent 97ee881 commit 683e1ed
Show file tree
Hide file tree
Showing 22 changed files with 310 additions and 255 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/upstream-dev-ci.yml
Expand Up @@ -47,7 +47,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
python-version: ["3.11"]
outputs:
artifacts_availability: ${{ steps.status.outputs.ARTIFACTS_AVAILABLE }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/xskillscore_installs.yml
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/xskillscore_testing.yml
Expand Up @@ -34,7 +34,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9]
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- name: Set up conda
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
channels: conda-forge
mamba-version: "*"
activate-environment: xskillscore-minimum-tests
python-version: 3.8
python-version: 3.9
- name: Set up conda environment
run: |
mamba env update -f ci/minimum-tests.yml
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
channels: conda-forge
mamba-version: "*"
activate-environment: xskillscore-docs-notebooks
python-version: 3.8
python-version: 3.9
- name: Set up conda environment
run: |
mamba env update -f ci/docs_notebooks.yml
Expand Down
96 changes: 67 additions & 29 deletions .pre-commit-config.yaml
@@ -1,47 +1,85 @@
default_language_version:
python: python3

ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
autofix_prs: true
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: quarterly
skip: []
submodules: false

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: no-commit-to-branch
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-docstring-first
- id: end-of-file-fixer
- id: check-json
exclude: 'asv.conf.json'
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
args: [ '--allow-multiple-documents' ]
- id: debug-statements
- id: end-of-file-fixer
- id: no-commit-to-branch
- id: pretty-format-json
args: [ '--autofix', '--no-ensure-ascii', '--no-sort-keys' ]
exclude: '.ipynb|asv.conf.json'
- id: trailing-whitespace

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.1
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8

- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
hooks:
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: blackdoc
additional_dependencies: [ 'black==23.10.1' ]

- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
hooks:
- id: doc8
args: ["--max-line-length", "100",
"--allow-long-titles",
"--ignore-path", "docs/source/api/"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
hooks:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
hooks:
- id: mypy
exclude: "asv_bench"
args:
- --ignore-missing-imports
- --follow-imports=silent
- --install-types
- --non-interactive
exclude: 'asv_bench'
additional_dependencies: [
# Type stubs
types-python-dateutil,
types-pkg_resources,
types-PyYAML,
types-pytz,
typing-extensions==3.10.0.0,
# Dependencies that are typed
numpy,
]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.0
hooks:
- id: check-github-workflows
- id: check-readthedocs
1 change: 0 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -2,7 +2,6 @@
Changelog History
=================


xskillscore v0.0.25 (2021-xx-xx)
--------------------------------

Expand Down
1 change: 0 additions & 1 deletion asv_bench/benchmarks/__init__.py
Expand Up @@ -56,7 +56,6 @@ class Generate:
repeat = (2, 5, 20)

def make_ds(self, nmember, nx, ny, chunks=None):

# ds
self.ds = xr.Dataset()
self.nmember = nmember
Expand Down
2 changes: 1 addition & 1 deletion ci/doc.yml
Expand Up @@ -2,7 +2,7 @@ name: xskillscore-docs
channels:
- conda-forge
dependencies:
- python=3.8
- python >=3.9
- bottleneck
- doc8
- ipykernel
Expand Down
9 changes: 7 additions & 2 deletions readthedocs.yml
@@ -1,9 +1,9 @@
version: 2

build:
os: "ubuntu-20.04"
os: "ubuntu-22.04"
tools:
python: "mambaforge-4.10"
python: "mambaforge-22.9"

conda:
environment: ci/doc.yml
Expand All @@ -12,3 +12,8 @@ sphinx:
fail_on_warning: false

formats: []

python:
install:
- method: pip
path: .
3 changes: 3 additions & 0 deletions setup.cfg
@@ -1,6 +1,9 @@
[tool:pytest]
python_files = test_*.py
testpaths = xskillscore/tests
addopts =
--color=yes
--verbose
markers =
slow: marks tests as slow (deselect with '-m "not slow"')

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -9,7 +9,7 @@
URL = "https://github.com/xarray-contrib/xskillscore"
with open("requirements.txt") as f:
INSTALL_REQUIRES = f.read().strip().split("\n")
PYTHON_REQUIRE = ">=3.8"
PYTHON_REQUIRE = ">=3.9"

EXTRAS_REQUIRE = {
"accel": ["numba>=0.52", "bottleneck"],
Expand All @@ -24,7 +24,7 @@
"matplotlib",
"pytest-cov",
"pytest-xdist",
"pytest-lazyfixures",
"pytest-lazy-fixures",
"pre-commit",
]
EXTRAS_REQUIRE["docs"] = EXTRAS_REQUIRE["complete"] + [
Expand Down
6 changes: 3 additions & 3 deletions xskillscore/__init__.py
@@ -1,5 +1,5 @@
# flake8: noqa
from pkg_resources import DistributionNotFound, get_distribution # type: ignore
from importlib.metadata import PackageNotFoundError, version as _get_version

from .core import resampling
from .core.accessor import XSkillScoreAccessor
Expand Down Expand Up @@ -40,7 +40,7 @@
from .versioning.print_versions import show_versions

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
__version__ = _get_version("xskillscore")
except PackageNotFoundError: # pragma: no cover
# package is not installed
pass
27 changes: 11 additions & 16 deletions xskillscore/core/comparative.py
Expand Up @@ -80,19 +80,17 @@ def sign_test(
Examples
--------
>>> f1 = xr.DataArray(np.random.normal(size=(30)),
... coords=[('time', np.arange(30))])
>>> f1 = xr.DataArray(np.random.normal(size=(30)), coords=[("time", np.arange(30))])
>>> f2 = f1 + 2
>>> o = xr.DataArray(np.random.normal(size=(30)),
... coords=[('time', np.arange(30))])
>>> o = xr.DataArray(np.random.normal(size=(30)), coords=[("time", np.arange(30))])
>>> significantly_different, walk, confidence = xs.sign_test(
... f1, f2, o, time_dim='time', metric='mae', orientation='negative'
... f1, f2, o, time_dim="time", metric="mae", orientation="negative"
... )
>>> walk.plot() # doctest: +ELLIPSIS
>>> walk.plot() # doctest: +ELLIPSIS
[<matplotlib.lines.Line2D object at 0x...>]
>>> confidence.plot(color='gray') # doctest: +ELLIPSIS
>>> confidence.plot(color="gray") # doctest: +ELLIPSIS
[<matplotlib.lines.Line2D object at 0x...>]
>>> (-1 * confidence).plot(color='gray') # doctest: +ELLIPSIS
>>> (-1 * confidence).plot(color="gray") # doctest: +ELLIPSIS
[<matplotlib.lines.Line2D object at 0x...>]
>>> walk
<xarray.DataArray (time: 30)>
Expand Down Expand Up @@ -268,14 +266,11 @@ def halfwidth_ci_test(
Examples
--------
>>> f1 = xr.DataArray(np.random.normal(size=(30)),
... coords=[('time', np.arange(30))])
>>> f2 = xr.DataArray(np.random.normal(size=(30)),
... coords=[('time', np.arange(30))])
>>> o = xr.DataArray(np.random.normal(size=(30)),
... coords=[('time', np.arange(30))])
>>> f1 = xr.DataArray(np.random.normal(size=(30)), coords=[("time", np.arange(30))])
>>> f2 = xr.DataArray(np.random.normal(size=(30)), coords=[("time", np.arange(30))])
>>> o = xr.DataArray(np.random.normal(size=(30)), coords=[("time", np.arange(30))])
>>> significantly_different, diff, hwci = xs.halfwidth_ci_test(
... f1, f2, o, "mae", time_dim='time', dim=[], alpha=0.05
... f1, f2, o, "mae", time_dim="time", dim=[], alpha=0.05
... )
>>> significantly_different
<xarray.DataArray ()>
Expand All @@ -290,7 +285,7 @@ def halfwidth_ci_test(
>>> # confidence interval, therefore not significant at level alpha=0.05
>>> # now comparing against an offset f2, the difference in MAE is significant
>>> significantly_different, diff, hwci = xs.halfwidth_ci_test(
... f1, f2 + 2., o, "mae", time_dim='time', dim=[], alpha=0.05
... f1, f2 + 2.0, o, "mae", time_dim="time", dim=[], alpha=0.05
... )
>>> significantly_different
<xarray.DataArray ()>
Expand Down
14 changes: 8 additions & 6 deletions xskillscore/core/contingency.py
Expand Up @@ -74,15 +74,17 @@ class Contingency:
Examples
--------
>>> da = xr.DataArray(np.random.normal(size=(3, 3)),
... coords=[("x", np.arange(3)), ("y", np.arange(3))])
>>> da = xr.DataArray(
... np.random.normal(size=(3, 3)),
... coords=[("x", np.arange(3)), ("y", np.arange(3))],
... )
>>> o = xr.Dataset({"var1": da, "var2": da})
>>> f = o * 1.1
>>> o_category_edges = np.linspace(-2, 2, 5)
>>> f_category_edges = np.linspace(-3, 3, 5)
>>> xs.Contingency(o, f,
... o_category_edges, f_category_edges,
... dim=['x', 'y']) # doctest: +SKIP
>>> xs.Contingency(
... o, f, o_category_edges, f_category_edges, dim=["x", "y"]
... ) # doctest: +SKIP
<xskillscore.Contingency>
Dimensions: (forecasts_category: 4, observations_category: 4)
Coordinates:
Expand Down Expand Up @@ -774,7 +776,7 @@ def _gerrity_s(table):
a = (1.0 - p_sum) / p_sum
k = a.shape[-1]
s = np.zeros(table.shape, dtype=float)
for (i, j) in np.ndindex(*s.shape[-2:]):
for i, j in np.ndindex(*s.shape[-2:]):
if i == j:
s[..., i, j] = (
1.0
Expand Down

0 comments on commit 683e1ed

Please sign in to comment.