Skip to content

Commit 0438a7e

Browse files
authored
Drop python 3.9, use ruff (#392)
* Drop python 3.9, use ruff * switch to Ruff * fix mypy * remove toctrees * fix
1 parent 51310a3 commit 0438a7e

22 files changed

+384
-297
lines changed

.github/workflows/ci.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
matrix:
2727
os: ["ubuntu-latest"]
2828
env: ["environment"]
29-
python-version: ["3.9", "3.12"]
29+
python-version: ["3.10", "3.12"]
3030
include:
3131
- os: "windows-latest"
3232
env: "environment"
@@ -36,7 +36,7 @@ jobs:
3636
python-version: "3.12"
3737
- os: "ubuntu-latest"
3838
env: "minimal-requirements"
39-
python-version: "3.9"
39+
python-version: "3.10"
4040
steps:
4141
- uses: actions/checkout@v4
4242
with:

.pre-commit-config.yaml

+3-14
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ ci:
44
repos:
55
- repo: https://github.com/astral-sh/ruff-pre-commit
66
# Ruff version.
7-
rev: "v0.5.0"
7+
rev: "v0.6.4"
88
hooks:
99
- id: ruff
1010
args: ["--fix", "--show-fixes"]
11+
- id: ruff-format
1112

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

25-
- repo: https://github.com/psf/black-pre-commit-mirror
26-
rev: 24.4.2
27-
hooks:
28-
- id: black
29-
3026
- repo: https://github.com/executablebooks/mdformat
3127
rev: 0.7.17
3228
hooks:
@@ -35,13 +31,6 @@ repos:
3531
- mdformat-black
3632
- mdformat-myst
3733

38-
- repo: https://github.com/nbQA-dev/nbQA
39-
rev: 1.8.5
40-
hooks:
41-
- id: nbqa-black
42-
- id: nbqa-ruff
43-
args: [--fix]
44-
4534
- repo: https://github.com/kynan/nbstripout
4635
rev: 0.7.1
4736
hooks:
@@ -56,7 +45,7 @@ repos:
5645
- tomli
5746

5847
- repo: https://github.com/abravalheri/validate-pyproject
59-
rev: v0.18
48+
rev: v0.19
6049
hooks:
6150
- id: validate-pyproject
6251

asv_bench/benchmarks/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def _skip_slow():
2121
>>> from . import _skip_slow
2222
>>> def time_something_slow():
2323
... pass
24-
...
2524
>>> time_something.setup = _skip_slow
2625
"""
2726
if os.environ.get("ASV_SKIP_SLOW", "0") == "1":

asv_bench/benchmarks/cohorts.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ def track_num_layers(self):
6767
track_num_tasks.unit = "tasks" # type: ignore[attr-defined] # Lazy
6868
track_num_tasks_optimized.unit = "tasks" # type: ignore[attr-defined] # Lazy
6969
track_num_layers.unit = "layers" # type: ignore[attr-defined] # Lazy
70-
for f in [track_num_tasks, track_num_tasks_optimized, track_num_layers, track_num_cohorts]:
70+
for f in [
71+
track_num_tasks,
72+
track_num_tasks_optimized,
73+
track_num_layers,
74+
track_num_cohorts,
75+
]:
7176
f.repeat = 1 # type: ignore[attr-defined] # Lazy
7277
f.rounds = 1 # type: ignore[attr-defined] # Lazy
7378
f.number = 1 # type: ignore[attr-defined] # Lazy
@@ -82,9 +87,7 @@ def setup(self, *args, **kwargs):
8287
y = np.repeat(np.arange(30), 60)
8388
by = x[np.newaxis, :] * y[:, np.newaxis]
8489

85-
self.by = flox.core._factorize_multiple((by,), expected_groups=(None,), any_by_dask=False)[
86-
0
87-
][0]
90+
self.by = flox.core._factorize_multiple((by,), expected_groups=(None,), any_by_dask=False)[0][0]
8891

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

102105
def rechunk(self):
103106
self.array = flox.core.rechunk_for_cohorts(
104-
self.array, -1, self.by, force_new_chunk_at=[1], chunksize=48, ignore_old_chunks=True
107+
self.array,
108+
-1,
109+
self.by,
110+
force_new_chunk_at=[1],
111+
chunksize=48,
112+
ignore_old_chunks=True,
105113
)
106114

107115

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

152160
def rechunk(self):
153161
self.array = flox.core.rechunk_for_cohorts(
154-
self.array, -1, self.by, force_new_chunk_at=[1], chunksize=4, ignore_old_chunks=True
162+
self.array,
163+
-1,
164+
self.by,
165+
force_new_chunk_at=[1],
166+
chunksize=4,
167+
ignore_old_chunks=True,
155168
)
156169

157170

asv_bench/benchmarks/combine.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,8 @@ def construct_member(groups) -> dict[str, Any]:
6565
* 2
6666
]
6767

68-
self.x_chunk_reindexed = [
69-
construct_member(groups) for groups in [np.array((1, 2, 3, 4))] * 4
70-
]
68+
self.x_chunk_reindexed = [construct_member(groups) for groups in [np.array((1, 2, 3, 4))] * 4]
7169
self.kwargs = {
72-
"agg": flox.aggregations._initialize_aggregation(
73-
"sum", "float64", np.float64, 0, 0, {}
74-
),
70+
"agg": flox.aggregations._initialize_aggregation("sum", "float64", np.float64, 0, 0, {}),
7571
"axis": (3,),
7672
}

asv_bench/benchmarks/reduce.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
N = 3000
99
funcs = ["sum", "nansum", "mean", "nanmean", "max", "nanmax", "count"]
10-
engines = [None, "flox", "numpy"] # numbagg is disabled for now since it takes ages in CI
10+
engines = [
11+
None,
12+
"flox",
13+
"numpy",
14+
] # numbagg is disabled for now since it takes ages in CI
1115
expected_groups = {
1216
"None": None,
1317
"bins": pd.IntervalIndex.from_breaks([1, 2, 4]),
@@ -17,9 +21,7 @@
1721
NUMBAGG_FUNCS = ["nansum", "nanmean", "nanmax", "count", "all"]
1822
numbagg_skip = []
1923
for name in expected_names:
20-
numbagg_skip.extend(
21-
list((func, name, "numbagg") for func in funcs if func not in NUMBAGG_FUNCS)
22-
)
24+
numbagg_skip.extend(list((func, name, "numbagg") for func in funcs if func not in NUMBAGG_FUNCS))
2325

2426

2527
def setup_jit():

ci/docs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies:
1616
- myst-parser
1717
- myst-nb
1818
- sphinx
19+
- sphinx-remove-toctrees
1920
- furo>=2024.08
2021
- ipykernel
2122
- jupyter

docs/source/conf.py

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"sphinx.ext.napoleon",
4141
"myst_nb",
4242
"sphinx_codeautolink",
43+
"sphinx_remove_toctrees",
4344
]
4445

4546
codeautolink_concat_default = True
@@ -54,6 +55,8 @@
5455
master_doc = "index"
5556
language = "en"
5657

58+
remove_from_toctrees = ["generated/*"]
59+
5760
# General information about the project.
5861
project = "flox"
5962
current_year = datetime.datetime.now().year

docs/source/user-stories/climatology-hourly.ipynb

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
"%load_ext watermark\n",
9393
"\n",
9494
"\n",
95-
"\n",
9695
"%watermark -iv"
9796
]
9897
},

flox/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/usr/bin/env python
22
# flake8: noqa
33
"""Top-level module for flox ."""
4+
45
from . import cache
56
from .aggregations import Aggregation, Scan # noqa
6-
from .core import groupby_reduce, groupby_scan, rechunk_for_blockwise, rechunk_for_cohorts # noqa
7+
from .core import (
8+
groupby_reduce,
9+
groupby_scan,
10+
rechunk_for_blockwise,
11+
rechunk_for_cohorts,
12+
) # noqa
713

814

915
def _get_version():

flox/aggregate_flox.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,14 @@ def quantile_(array, inv_idx, *, q, axis, skipna, group_idx, dtype=None, out=Non
8989
idxshape = (q.shape[0],) + array.shape[:-1] + (actual_sizes.shape[-1],)
9090

9191
lo_ = np.floor(
92-
virtual_index, casting="unsafe", out=np.empty(virtual_index.shape, dtype=np.int64)
92+
virtual_index,
93+
casting="unsafe",
94+
out=np.empty(virtual_index.shape, dtype=np.int64),
9395
)
9496
hi_ = np.ceil(
95-
virtual_index, casting="unsafe", out=np.empty(virtual_index.shape, dtype=np.int64)
97+
virtual_index,
98+
casting="unsafe",
99+
out=np.empty(virtual_index.shape, dtype=np.int64),
96100
)
97101
kth = np.unique(np.concatenate([lo_.reshape(-1), hi_.reshape(-1)]))
98102

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

120124

121125
def _np_grouped_op(
122-
group_idx, array, op, axis=-1, size=None, fill_value=None, dtype=None, out=None, **kwargs
126+
group_idx,
127+
array,
128+
op,
129+
axis=-1,
130+
size=None,
131+
fill_value=None,
132+
dtype=None,
133+
out=None,
134+
**kwargs,
123135
):
124136
"""
125137
most of this code is from shoyer's gist

0 commit comments

Comments
 (0)