Skip to content

Commit

Permalink
Merge branch 'main' into schema_to_json
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 authored Aug 9, 2024
2 parents c43d917 + 72d9960 commit 40ab4fe
Show file tree
Hide file tree
Showing 32 changed files with 952 additions and 530 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ updates:
directory: "/"
schedule:
interval: daily
groups:
pip-updates:
patterns:
- "*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
groups:
gh-actions:
patterns:
- "*"
18 changes: 9 additions & 9 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4.4.0
uses: actions/setup-python@v5.1.1
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/dev-requirements.txt') }}
Expand All @@ -39,7 +39,7 @@ jobs:
run: |
pytest --verbose --cov=. --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.1
uses: codecov/codecov-action@v4.5.0
if: ${{ matrix.python-version }} == 3.9
with:
file: ./coverage.xml
Expand All @@ -50,17 +50,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.10"]
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4.4.0
uses: actions/setup-python@v5.1.1
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: |
python -m pip install -e .[dev]
python -m pip install --no-deps --upgrade \
python -m pip install --upgrade \
git+https://github.com/dask/dask \
git+https://github.com/pydata/xarray
python -m pip list
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/pypi-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
runs-on: ubuntu-latest
if: github.repository == 'xarray-contrib/xbatcher'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4.4.0
- uses: actions/setup-python@v5.1.1
name: Install Python
with:
python-version: 3.8
python-version: 3.11

- name: Install dependencies
run: |
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
else
echo "✅ Looks good"
fi
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: releases
path: dist
Expand All @@ -62,11 +62,11 @@ jobs:
needs: build-artifacts
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4.4.0
- uses: actions/setup-python@v5.1.1
name: Install Python
with:
python-version: 3.8
- uses: actions/download-artifact@v3
python-version: 3.10
- uses: actions/download-artifact@v4
with:
name: releases
path: dist
Expand All @@ -80,23 +80,23 @@ jobs:
python -m pip install dist/xbatcher*.whl
python -m xbatcher.util.print_versions
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@v1.6.4
uses: pypa/gh-action-pypi-publish@v1.9.0
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
repository-url: https://test.pypi.org/legacy/
# verbose: true

upload-to-pypi:
needs: test-built-dist
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: releases
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@v1.6.4
uses: pypa/gh-action-pypi-publish@v1.9.0
with:
password: ${{ secrets.PYPI_API_TOKEN }}
# verbose: true
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV

# Drafts your next Release notes as Pull Requests are merged into "main"
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
# with:
# config-name: my-config.yml
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/testpypi-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3.2.0
uses: actions/checkout@v4
with:
# fetch all history so that setuptools-scm works
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4.3.1
uses: actions/setup-python@v5.1.1
with:
python-version: "3.10"
python-version: "3.11"

- name: Install dependencies
run: python -m pip install build
Expand All @@ -49,8 +49,8 @@ jobs:
python -m xbatcher.util.print_versions
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@v1.6.4
uses: pypa/gh-action-pypi-publish@v1.9.0
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
repository-url: https://test.pypi.org/legacy/
# verbose: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ target/

# tests
.pytest_cache/*
.mypy_cache/
27 changes: 8 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -13,31 +13,20 @@ repos:
exclude: "asv_bench/asv.conf.json"
- id: check-yaml

- repo: https://github.com/psf/black
rev: 22.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.5"
hooks:
- id: black-jupyter

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/PyCQA/isort
rev: 5.11.4
hooks:
- id: isort
- id: ruff
args: ["--fix"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.4
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
rev: v1.11.0
hooks:
- id: mypy
additional_dependencies: [
Expand Down
9 changes: 5 additions & 4 deletions asv_bench/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
//
// "install_command": ["in-dir={env_dir} python -mpip install {wheel_file}"],
// "uninstall_command": ["return-code=any python -mpip uninstall -y {project}"],
// "build_command": [
// "python setup.py build",
// "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
// ],
"build_command": [
"python -m pip install build",
"python -m build --wheel -o {build_cache_dir} {build_dir}"
//"PIP_NO_BUILD_ISOLATION=false python -m pip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
],

// List of branches to benchmark. If not provided, defaults to "master"
// (for git) or "default" (for mercurial).
Expand Down
24 changes: 24 additions & 0 deletions asv_bench/benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import numpy as np


def parameterized(names, params):
"""
Copied from xarray benchmarks:
Expand All @@ -10,3 +13,24 @@ def decorator(func):
return func

return decorator


def randn(shape, frac_nan=None, chunks=None, seed=0):
"""
Copied from xarray benchmarks:
https://github.com/pydata/xarray/blob/main/asv_bench/benchmarks/__init__.py#L32-L46
"""
rng = np.random.RandomState(seed)
if chunks is None:
x = rng.standard_normal(shape)
else:
import dask.array as da

rng = da.random.RandomState(seed)
x = rng.standard_normal(shape, chunks=chunks)

if frac_nan is not None:
inds = rng.choice(range(x.size), int(x.size * frac_nan))
x.flat[inds] = np.nan

return x
39 changes: 39 additions & 0 deletions asv_bench/benchmarks/accessors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import numpy as np
import pandas as pd
import xarray as xr

import xbatcher # noqa: F401

from . import parameterized, randn

nx = 250
ny = 50
nt = 10

randn_xyt = randn((nx, ny, nt), frac_nan=0.1)


class Accessor:
def setup(self, *args, **kwargs):
self.ds = xr.Dataset(
{
'var1': (('x', 'y', 't'), randn_xyt),
},
coords={
'x': np.arange(nx),
'y': np.linspace(0, 1, ny),
't': pd.date_range('1970-01-01', periods=nt, freq='D'),
},
)

@parameterized(
['input_dims'],
([{'x': 10}, {'x': 10, 'y': 5}, {'x': 10, 'y': 5, 't': 2}],),
)
def time_input_dims(self, input_dims):
"""
Benchmark simple batch generation case using xarray accessor
Equivalent to subset of ``time_batch_input()``.
"""
bg = self.ds.batch.generator(input_dims=input_dims)
bg[0]
Loading

0 comments on commit 40ab4fe

Please sign in to comment.