Skip to content

Commit 5913a35

Browse files
committed
pre-commit config added
github actions updated py3.12 enabled in tests
1 parent b5d8a12 commit 5913a35

File tree

7 files changed

+79
-25
lines changed

7 files changed

+79
-25
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ jobs:
2727
os: ["ubuntu-latest"]
2828
python-version: ["3.9", "3.10", "3.11", "3.12"]
2929
steps:
30-
- uses: actions/checkout@v3
30+
- uses: actions/checkout@v4
3131
with:
32-
fetch-depth: 10 # Fetch all history for all branches and tags.
32+
fetch-depth: 1
3333
- name: Set environment variables
3434
run: |
3535
echo "CONDA_ENV_FILE=ci/environment.yml" >> $GITHUB_ENV
@@ -49,7 +49,7 @@ jobs:
4949
# We only want to install this on one run, because otherwise we'll have
5050
# duplicate annotations.
5151
- name: Install error reporter
52-
if: ${{ matrix.os }} == 'ubuntu-latest' and ${{ matrix.python-version }} == '3.10'
52+
if: ${{ matrix.os }} == 'ubuntu-latest' and ${{ matrix.python-version }} == '3.11'
5353
run: |
5454
python -m pip install pytest-github-actions-annotate-failures
5555

.github/workflows/pypi-release.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
runs-on: ubuntu-latest
1313
if: github.repository == 'ml31415/numpy-groupies'
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
18-
- uses: actions/setup-python@v4
18+
- uses: actions/setup-python@v5
1919
name: Install Python
2020
with:
21-
python-version: "3.10"
21+
python-version: "3.11"
2222

2323
- name: Install dependencies
2424
run: |
@@ -39,7 +39,7 @@ jobs:
3939
else
4040
echo "✅ Looks good"
4141
fi
42-
- uses: actions/upload-artifact@v3
42+
- uses: actions/upload-artifact@v4
4343
with:
4444
name: releases
4545
path: dist
@@ -48,11 +48,11 @@ jobs:
4848
needs: build-artifacts
4949
runs-on: ubuntu-latest
5050
steps:
51-
- uses: actions/setup-python@v4
51+
- uses: actions/setup-python@v5
5252
name: Install Python
5353
with:
54-
python-version: "3.10"
55-
- uses: actions/download-artifact@v3
54+
python-version: "3.11"
55+
- uses: actions/download-artifact@v4
5656
with:
5757
name: releases
5858
path: dist
@@ -80,7 +80,7 @@ jobs:
8080
if: github.event_name == 'release'
8181
runs-on: ubuntu-latest
8282
steps:
83-
- uses: actions/download-artifact@v3
83+
- uses: actions/download-artifact@v4
8484
with:
8585
name: releases
8686
path: dist
@@ -89,4 +89,4 @@ jobs:
8989
with:
9090
user: __token__
9191
password: ${{ secrets.PYPI_TOKEN }}
92-
verbose: true
92+
verbose: true

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: debug-statements
6+
- id: detect-private-key
7+
- id: check-builtin-literals
8+
- id: check-case-conflict
9+
- id: check-executables-have-shebangs
10+
- id: check-json
11+
- id: check-merge-conflict
12+
- id: check-symlinks
13+
- id: check-toml
14+
- id: check-xml
15+
- id: check-yaml
16+
exclude: (.pre-commit-config\.yaml)
17+
18+
- repo: https://github.com/astral-sh/ruff-pre-commit
19+
rev: v0.3.7
20+
hooks:
21+
- id: ruff
22+
- id: ruff-format
23+
24+
- repo: https://github.com/codespell-project/codespell
25+
rev: v2.2.6
26+
hooks:
27+
- id: codespell

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[![GitHub Workflow CI Status](https://img.shields.io/github/actions/workflow/status/ml31415/numpy-groupies/ci.yaml?branch=master&logo=github&style=flat)](https://github.com/ml31415/numpy-groupies/actions)
22
[![PyPI](https://img.shields.io/pypi/v/numpy-groupies.svg?style=flat)](https://pypi.org/project/numpy-groupies/)
33
[![Conda-forge](https://img.shields.io/conda/vn/conda-forge/numpy_groupies.svg?style=flat)](https://anaconda.org/conda-forge/numpy_groupies)
4-
[![Supported Versions](https://img.shields.io/pypi/pyversions/numpy-groupies.svg)](https://pypi.org/project/numpy-groupies)
5-
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
4+
![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fml31415%2Fnumpy-groupies%2Fmaster%2Fpyproject.toml)
65
![PyPI - Downloads](https://img.shields.io/pypi/dm/numpy-groupies)
76

87
# numpy-groupies

numpy_groupies/benchmarks/generic.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ def benchmark_data(size=5e5, seed=100):
9191
def benchmark(implementations, repeat=5, size=5e5, seed=100, raise_errors=False):
9292
a, nana, group_idx = benchmark_data(size=size, seed=seed)
9393

94-
print("function" + "".join(impl.__name__.rsplit("_", 1)[1].rjust(14) for impl in implementations))
94+
print(
95+
"function"
96+
+ "".join(impl.__name__.rsplit("_", 1)[1].rjust(14) for impl in implementations)
97+
)
9598
print("-" * (9 + 14 * len(implementations)))
9699
for func in func_list:
97100
func_name = getattr(func, "__name__", func)
@@ -122,9 +125,9 @@ def benchmark(implementations, repeat=5, size=5e5, seed=100, raise_errors=False)
122125
print("FAIL".rjust(14), end="")
123126
else:
124127
t0 = min(
125-
timeit.Timer(lambda: aggregatefunc(group_idx, used_a, func=func)).repeat(
126-
repeat=repeat, number=1
127-
)
128+
timeit.Timer(
129+
lambda: aggregatefunc(group_idx, used_a, func=func)
130+
).repeat(repeat=repeat, number=1)
128131
)
129132
print(f"{t0 * 1000:.3f}".rjust(14), end="")
130133
sys.stdout.flush()
@@ -147,6 +150,10 @@ def benchmark(implementations, repeat=5, size=5e5, seed=100, raise_errors=False)
147150

148151

149152
if __name__ == "__main__":
150-
implementations = _implementations if "--purepy" in sys.argv else _implementations[1:]
151-
implementations = implementations if "--pandas" in sys.argv else implementations[:-1]
153+
implementations = (
154+
_implementations if "--purepy" in sys.argv else _implementations[1:]
155+
)
156+
implementations = (
157+
implementations if "--pandas" in sys.argv else implementations[:-1]
158+
)
152159
benchmark(implementations, raise_errors=False)

numpy_groupies/benchmarks/simple.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def aggregate_group_loop(*args, **kwargs):
2828
print("aggregate(test_group_idx, test_a, sz=8, func='min', fill_value=np.nan):")
2929
print(aggregate_np(test_group_idx, test_a, size=8, func="min", fill_value=np.nan))
3030
# array([3.2, -15., nan, 88., nan, nan, nan, nan])
31-
print("aggregate_py(test_group_idx, test_a, sz=5, func=lambda x: ' + '.join(str(xx) for xx in x),fill_value='')")
31+
print(
32+
"aggregate_py(test_group_idx, test_a, sz=5, func=lambda x: ' + '.join(str(xx) for xx in x),fill_value='')"
33+
)
3234
print(
3335
aggregate_py(
3436
test_group_idx,
@@ -43,7 +45,10 @@ def aggregate_group_loop(*args, **kwargs):
4345
print("")
4446
print("---------testing--------------")
4547
print("compare against group-and-loop with numpy")
46-
testable_funcs = {aliasing[f]: f for f in (np.sum, np.prod, np.any, np.all, np.min, np.max, np.std, np.var, np.mean)}
48+
testable_funcs = {
49+
aliasing[f]: f
50+
for f in (np.sum, np.prod, np.any, np.all, np.min, np.max, np.std, np.var, np.mean)
51+
}
4752
test_group_idx = np.random.randint(0, int(1e3), int(1e5))
4853
test_a = np.random.rand(int(1e5)) * 100 - 50
4954
test_a[test_a > 25] = 0 # for use with bool functions
@@ -73,7 +78,9 @@ def aggregate_group_loop(*args, **kwargs):
7378

7479
print("")
7580
print("----------benchmarking-------------")
76-
print("Note that the actual observed speedup depends on a variety of properties of the input.")
81+
print(
82+
"Note that the actual observed speedup depends on a variety of properties of the input."
83+
)
7784
print("Here we are using 100,000 indices uniformly picked from [0, 1000).")
7885
print("Specifically, about 25% of the values are 0 (for use with bool operations),")
7986
print("the remainder are uniformly distributed on [-50,25).")
@@ -109,12 +116,19 @@ def aggregate_group_loop(*args, **kwargs):
109116
func = f if acc_func is aggregate_group_loop else name
110117
reps = 3 if acc_func is aggregate_py else 20
111118
times[ii] = (
112-
timeit.Timer(lambda: acc_func(test_group_idx, test_a, func=func)).timeit(number=reps) / reps * 10
119+
timeit.Timer(
120+
lambda: acc_func(test_group_idx, test_a, func=func)
121+
).timeit(number=reps)
122+
/ reps
123+
* 10
113124
)
114125
print(f"{times[ii] * 1000:.1f}ms".rjust(13), end="")
115126
except NotImplementedError:
116127
print("no-impl".rjust(13), end="")
117128

118129
denom = min(t for t in times if t is not None)
119-
ratios = [("-".center(4) if t is None else str(round(t / denom, 1))).center(5) for t in times]
130+
ratios = [
131+
("-".center(4) if t is None else str(round(t / denom, 1))).center(5)
132+
for t in times
133+
]
120134
print(" ", (":".join(ratios)))

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,10 @@ include = ["numpy_groupies*"]
5959

6060
[tool.setuptools_scm]
6161
write_to = "numpy_groupies/_version.py"
62+
63+
[tool.ruff.lint.per-file-ignores]
64+
"__init__.py" = ["F401"]
65+
66+
[tool.codespell]
67+
ignore-words-list = "nd,"
68+
ignore-regex = ".*codespell-ignore$"

0 commit comments

Comments
 (0)