Skip to content

Drop python 3.9, use ruff #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
matrix:
os: ["ubuntu-latest"]
env: ["environment"]
python-version: ["3.9", "3.12"]
python-version: ["3.10", "3.12"]
include:
- os: "windows-latest"
env: "environment"
Expand All @@ -36,7 +36,7 @@ jobs:
python-version: "3.12"
- os: "ubuntu-latest"
env: "minimal-requirements"
python-version: "3.9"
python-version: "3.10"
steps:
- uses: actions/checkout@v4
with:
Expand Down
17 changes: 3 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ ci:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: "v0.5.0"
rev: "v0.6.4"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8"
Expand All @@ -22,11 +23,6 @@ repos:
- id: end-of-file-fixer
- id: check-docstring-first

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

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
Expand All @@ -35,13 +31,6 @@ repos:
- mdformat-black
- mdformat-myst

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.5
hooks:
- id: nbqa-black
- id: nbqa-ruff
args: [--fix]

- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
Expand All @@ -56,7 +45,7 @@ repos:
- tomli

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
rev: v0.19
hooks:
- id: validate-pyproject

Expand Down
1 change: 0 additions & 1 deletion asv_bench/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def _skip_slow():
>>> from . import _skip_slow
>>> def time_something_slow():
... pass
...
>>> time_something.setup = _skip_slow
"""
if os.environ.get("ASV_SKIP_SLOW", "0") == "1":
Expand Down
25 changes: 19 additions & 6 deletions asv_bench/benchmarks/cohorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def track_num_layers(self):
track_num_tasks.unit = "tasks" # type: ignore[attr-defined] # Lazy
track_num_tasks_optimized.unit = "tasks" # type: ignore[attr-defined] # Lazy
track_num_layers.unit = "layers" # type: ignore[attr-defined] # Lazy
for f in [track_num_tasks, track_num_tasks_optimized, track_num_layers, track_num_cohorts]:
for f in [
track_num_tasks,
track_num_tasks_optimized,
track_num_layers,
track_num_cohorts,
]:
f.repeat = 1 # type: ignore[attr-defined] # Lazy
f.rounds = 1 # type: ignore[attr-defined] # Lazy
f.number = 1 # type: ignore[attr-defined] # Lazy
Expand All @@ -82,9 +87,7 @@ def setup(self, *args, **kwargs):
y = np.repeat(np.arange(30), 60)
by = x[np.newaxis, :] * y[:, np.newaxis]

self.by = flox.core._factorize_multiple((by,), expected_groups=(None,), any_by_dask=False)[
0
][0]
self.by = flox.core._factorize_multiple((by,), expected_groups=(None,), any_by_dask=False)[0][0]

self.array = dask.array.ones(self.by.shape, chunks=(350, 350))
self.axis = (-2, -1)
Expand All @@ -101,7 +104,12 @@ def __init__(self, *args, **kwargs):

def rechunk(self):
self.array = flox.core.rechunk_for_cohorts(
self.array, -1, self.by, force_new_chunk_at=[1], chunksize=48, ignore_old_chunks=True
self.array,
-1,
self.by,
force_new_chunk_at=[1],
chunksize=48,
ignore_old_chunks=True,
)


Expand Down Expand Up @@ -151,7 +159,12 @@ def setup(self, *args, **kwargs):

def rechunk(self):
self.array = flox.core.rechunk_for_cohorts(
self.array, -1, self.by, force_new_chunk_at=[1], chunksize=4, ignore_old_chunks=True
self.array,
-1,
self.by,
force_new_chunk_at=[1],
chunksize=4,
ignore_old_chunks=True,
)


Expand Down
8 changes: 2 additions & 6 deletions asv_bench/benchmarks/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ def construct_member(groups) -> dict[str, Any]:
* 2
]

self.x_chunk_reindexed = [
construct_member(groups) for groups in [np.array((1, 2, 3, 4))] * 4
]
self.x_chunk_reindexed = [construct_member(groups) for groups in [np.array((1, 2, 3, 4))] * 4]
self.kwargs = {
"agg": flox.aggregations._initialize_aggregation(
"sum", "float64", np.float64, 0, 0, {}
),
"agg": flox.aggregations._initialize_aggregation("sum", "float64", np.float64, 0, 0, {}),
"axis": (3,),
}
10 changes: 6 additions & 4 deletions asv_bench/benchmarks/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

N = 3000
funcs = ["sum", "nansum", "mean", "nanmean", "max", "nanmax", "count"]
engines = [None, "flox", "numpy"] # numbagg is disabled for now since it takes ages in CI
engines = [
None,
"flox",
"numpy",
] # numbagg is disabled for now since it takes ages in CI
expected_groups = {
"None": None,
"bins": pd.IntervalIndex.from_breaks([1, 2, 4]),
Expand All @@ -17,9 +21,7 @@
NUMBAGG_FUNCS = ["nansum", "nanmean", "nanmax", "count", "all"]
numbagg_skip = []
for name in expected_names:
numbagg_skip.extend(
list((func, name, "numbagg") for func in funcs if func not in NUMBAGG_FUNCS)
)
numbagg_skip.extend(list((func, name, "numbagg") for func in funcs if func not in NUMBAGG_FUNCS))


def setup_jit():
Expand Down
1 change: 1 addition & 0 deletions ci/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
- myst-parser
- myst-nb
- sphinx
- sphinx-remove-toctrees
- furo>=2024.08
- ipykernel
- jupyter
Expand Down
3 changes: 3 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"sphinx.ext.napoleon",
"myst_nb",
"sphinx_codeautolink",
"sphinx_remove_toctrees",
]

codeautolink_concat_default = True
Expand All @@ -54,6 +55,8 @@
master_doc = "index"
language = "en"

remove_from_toctrees = ["generated/*"]

# General information about the project.
project = "flox"
current_year = datetime.datetime.now().year
Expand Down
1 change: 0 additions & 1 deletion docs/source/user-stories/climatology-hourly.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"%load_ext watermark\n",
"\n",
"\n",
"\n",
"%watermark -iv"
]
},
Expand Down
8 changes: 7 additions & 1 deletion flox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/usr/bin/env python
# flake8: noqa
"""Top-level module for flox ."""

from . import cache
from .aggregations import Aggregation, Scan # noqa
from .core import groupby_reduce, groupby_scan, rechunk_for_blockwise, rechunk_for_cohorts # noqa
from .core import (
groupby_reduce,
groupby_scan,
rechunk_for_blockwise,
rechunk_for_cohorts,
) # noqa


def _get_version():
Expand Down
18 changes: 15 additions & 3 deletions flox/aggregate_flox.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ def quantile_(array, inv_idx, *, q, axis, skipna, group_idx, dtype=None, out=Non
idxshape = (q.shape[0],) + array.shape[:-1] + (actual_sizes.shape[-1],)

lo_ = np.floor(
virtual_index, casting="unsafe", out=np.empty(virtual_index.shape, dtype=np.int64)
virtual_index,
casting="unsafe",
out=np.empty(virtual_index.shape, dtype=np.int64),
)
hi_ = np.ceil(
virtual_index, casting="unsafe", out=np.empty(virtual_index.shape, dtype=np.int64)
virtual_index,
casting="unsafe",
out=np.empty(virtual_index.shape, dtype=np.int64),
)
kth = np.unique(np.concatenate([lo_.reshape(-1), hi_.reshape(-1)]))

Expand All @@ -119,7 +123,15 @@ def quantile_(array, inv_idx, *, q, axis, skipna, group_idx, dtype=None, out=Non


def _np_grouped_op(
group_idx, array, op, axis=-1, size=None, fill_value=None, dtype=None, out=None, **kwargs
group_idx,
array,
op,
axis=-1,
size=None,
fill_value=None,
dtype=None,
out=None,
**kwargs,
):
"""
most of this code is from shoyer's gist
Expand Down
Loading
Loading