Skip to content

Commit 0d7a560

Browse files
committed
Add some numpydoc validation checks
1 parent aa46b45 commit 0d7a560

File tree

6 files changed

+79
-104
lines changed

6 files changed

+79
-104
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ repos:
99
- repo: https://github.com/astral-sh/ruff-pre-commit
1010
rev: v0.6.9
1111
hooks:
12-
- id: ruff
13-
args: ["--fix", "--show-fixes"]
14-
- id: ruff-format
12+
- id: ruff
13+
args: ["--fix", "--show-fixes"]
14+
- id: ruff-format
1515
- repo: https://github.com/codespell-project/codespell
1616
rev: v2.3.0
1717
hooks:
@@ -20,7 +20,7 @@ repos:
2020
- repo: https://github.com/pre-commit/pre-commit-hooks
2121
rev: v5.0.0
2222
hooks:
23-
- id: check-yaml
23+
- id: check-yaml
2424
- repo: https://github.com/pre-commit/mirrors-mypy
2525
rev: v1.11.2
2626
hooks:
@@ -49,3 +49,7 @@ repos:
4949
hooks:
5050
- id: rst-directive-colons
5151
- id: rst-inline-touching-normal
52+
- repo: https://github.com/numpy/numpydoc
53+
rev: v1.8.0
54+
hooks:
55+
- id: numpydoc-validation

pyproject.toml

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ build-backend = "hatchling.build"
77
name = "zarr"
88
description = "An implementation of chunked, compressed, N-dimensional arrays for Python"
99
readme = { file = "README.md", content-type = "text/markdown" }
10-
authors = [
11-
{ name = "Alistair Miles", email = "[email protected]" },
12-
]
10+
authors = [{ name = "Alistair Miles", email = "[email protected]" }]
1311
maintainers = [
1412
{ name = "Davis Bennett", email = "[email protected]" },
1513
{ name = "jakirkham" },
@@ -18,7 +16,7 @@ maintainers = [
1816
{ name = "Juan Nunez-Iglesias", email = "[email protected]" },
1917
{ name = "Martin Durant", email = "[email protected]" },
2018
{ name = "Norman Rzepka" },
21-
{ name = "Ryan Abernathey" }
19+
{ name = "Ryan Abernathey" },
2220
]
2321
requires-python = ">=3.11"
2422
# If you add a new dependency here, please also add it to .pre-commit-config.yml
@@ -32,9 +30,7 @@ dependencies = [
3230
'typing_extensions',
3331
'donfig',
3432
]
35-
dynamic = [
36-
"version",
37-
]
33+
dynamic = ["version"]
3834
classifiers = [
3935
'Development Status :: 6 - Mature',
4036
'Intended Audience :: Developers',
@@ -48,7 +44,7 @@ classifiers = [
4844
'Programming Language :: Python :: 3.11',
4945
'Programming Language :: Python :: 3.12',
5046
]
51-
license = {text = "MIT License"}
47+
license = { text = "MIT License" }
5248
keywords = ["Python", "compressed", "ndimensional-arrays", "zarr"]
5349

5450
[project.optional-dependencies]
@@ -69,14 +65,8 @@ test = [
6965
"universal-pathlib",
7066
]
7167

72-
jupyter = [
73-
'notebook',
74-
'ipytree>=0.2.2',
75-
'ipywidgets>=8.0.0',
76-
]
77-
gpu = [
78-
"cupy-cuda12x",
79-
]
68+
jupyter = ['notebook', 'ipytree>=0.2.2', 'ipywidgets>=8.0.0']
69+
gpu = ["cupy-cuda12x"]
8070
docs = [
8171
'sphinx==8.0.2',
8272
'sphinx-autobuild>=2021.3.14',
@@ -90,13 +80,8 @@ docs = [
9080
'msgpack',
9181
'lmdb',
9282
]
93-
extra = [
94-
'msgpack',
95-
]
96-
optional = [
97-
'lmdb',
98-
'universal-pathlib',
99-
]
83+
extra = ['msgpack']
84+
optional = ['lmdb', 'universal-pathlib']
10085

10186
[project.urls]
10287
"Bug Tracker" = "https://github.com/zarr-developers/zarr-python/issues"
@@ -106,26 +91,17 @@ Documentation = "https://zarr.readthedocs.io/"
10691
Homepage = "https://github.com/zarr-developers/zarr-python"
10792

10893
[tool.coverage.report]
109-
exclude_lines = [
110-
"pragma: no cover",
111-
"pragma: ${PY_MAJOR_VERSION} no cover",
112-
]
94+
exclude_lines = ["pragma: no cover", "pragma: ${PY_MAJOR_VERSION} no cover"]
11395

11496
[tool.coverage.run]
115-
omit = [
116-
"src/zarr/meta_v1.py",
117-
"bench/compress_normal.py",
118-
]
97+
omit = ["src/zarr/meta_v1.py", "bench/compress_normal.py"]
11998

12099
[tool.hatch]
121100
version.source = "vcs"
122101
build.hooks.vcs.version-file = "src/zarr/_version.py"
123102

124103
[tool.hatch.envs.test]
125-
dependencies = [
126-
"numpy~={matrix:numpy}",
127-
"universal_pathlib",
128-
]
104+
dependencies = ["numpy~={matrix:numpy}", "universal_pathlib"]
129105
features = ["test", "extra"]
130106

131107
[[tool.hatch.envs.test.matrix]]
@@ -153,10 +129,7 @@ run-hypothesis = "pytest --hypothesis-profile ci tests/v3/test_properties.py tes
153129
list-env = "pip list"
154130

155131
[tool.hatch.envs.gputest]
156-
dependencies = [
157-
"numpy~={matrix:numpy}",
158-
"universal_pathlib",
159-
]
132+
dependencies = ["numpy~={matrix:numpy}", "universal_pathlib"]
160133
features = ["test", "extra", "gpu"]
161134

162135
[[tool.hatch.envs.gputest.matrix]]
@@ -197,7 +170,7 @@ extend-exclude = [
197170
"buck-out",
198171
"build",
199172
"dist",
200-
"notebooks", # temporary, until we achieve compatibility with ruff ≥ 0.6
173+
"notebooks", # temporary, until we achieve compatibility with ruff ≥ 0.6
201174
"venv",
202175
"docs",
203176
"src/zarr/v2/",
@@ -267,9 +240,7 @@ warn_unreachable = true
267240
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
268241

269242
[[tool.mypy.overrides]]
270-
module = [
271-
"zarr.v2.*",
272-
]
243+
module = ["zarr.v2.*"]
273244
ignore_errors = true
274245

275246
[[tool.mypy.overrides]]
@@ -300,22 +271,22 @@ doctest_optionflags = [
300271
"ELLIPSIS",
301272
"IGNORE_EXCEPTION_DETAIL",
302273
]
303-
addopts = [
304-
"--durations=10", "-ra", "--strict-config", "--strict-markers",
305-
]
274+
addopts = ["--durations=10", "-ra", "--strict-config", "--strict-markers"]
306275
filterwarnings = [
307276
"error:::zarr.*",
308277
"ignore:PY_SSIZE_T_CLEAN will be required.*:DeprecationWarning",
309278
"ignore:The loop argument is deprecated since Python 3.8.*:DeprecationWarning",
310279
"ignore:Creating a zarr.buffer.gpu.*:UserWarning",
311-
"ignore:Duplicate name:UserWarning", # from ZipFile
312-
]
313-
markers = [
314-
"gpu: mark a test as requiring CuPy and GPU"
280+
"ignore:Duplicate name:UserWarning", # from ZipFile
315281
]
282+
markers = ["gpu: mark a test as requiring CuPy and GPU"]
316283

317284
[tool.repo-review]
318285
ignore = [
319-
"PC111", # fix Python code in documentation - enable later
320-
"PC180", # for JavaScript - not interested
286+
"PC111", # fix Python code in documentation - enable later
287+
"PC180", # for JavaScript - not interested
321288
]
289+
290+
[tool.numpydoc_validation]
291+
# See https://numpydoc.readthedocs.io/en/latest/validation.html#built-in-validation-checks for list of checks
292+
checks = ["GL06", "GL07", "GL10", "PR03", "PR05", "PR06"]

src/zarr/api/asynchronous.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ async def load(
159159
160160
Parameters
161161
----------
162-
store : Store or string
162+
store : Store or str
163163
Store or path to directory in file system or name of zip file.
164164
path : str or None, optional
165165
The path within the store from which to load.
@@ -203,7 +203,7 @@ async def open(
203203
204204
Parameters
205205
----------
206-
store : Store or string, optional
206+
store : Store or str, optional
207207
Store or path to directory in file system or name of zip file.
208208
mode : {'r', 'r+', 'a', 'w', 'w-'}, optional
209209
Persistence mode: 'r' means read only (must exist); 'r+' means
@@ -267,7 +267,7 @@ async def save(
267267
268268
Parameters
269269
----------
270-
store : Store or string
270+
store : Store or str
271271
Store or path to directory in file system or name of zip file.
272272
args : ndarray
273273
NumPy arrays with data to save.
@@ -303,7 +303,7 @@ async def save_array(
303303
304304
Parameters
305305
----------
306-
store : Store or string
306+
store : Store or str
307307
Store or path to directory in file system or name of zip file.
308308
arr : ndarray
309309
NumPy array with data to save.
@@ -351,7 +351,7 @@ async def save_group(
351351
352352
Parameters
353353
----------
354-
store : Store or string
354+
store : Store or str
355355
Store or path to directory in file system or name of zip file.
356356
args : ndarray
357357
NumPy arrays with data to save.
@@ -467,7 +467,7 @@ async def group(
467467
468468
Parameters
469469
----------
470-
store : Store or string, optional
470+
store : Store or str, optional
471471
Store or path to directory in file system.
472472
overwrite : bool, optional
473473
If True, delete any pre-existing data in `store` at `path` before
@@ -481,7 +481,7 @@ async def group(
481481
to all attribute read operations.
482482
synchronizer : object, optional
483483
Array synchronizer.
484-
path : string, optional
484+
path : str, optional
485485
Group path within store.
486486
meta_array : array-like, optional
487487
An array instance to use for determining arrays to create and return
@@ -547,7 +547,7 @@ async def open_group(
547547
548548
Parameters
549549
----------
550-
store : Store, string, or mapping, optional
550+
store : Store, str, or mapping, optional
551551
Store or path to directory in file system or name of zip file.
552552
553553
Strings are interpreted as paths on the local file system
@@ -570,9 +570,9 @@ async def open_group(
570570
to all attribute read operations.
571571
synchronizer : object, optional
572572
Array synchronizer.
573-
path : string, optional
573+
path : str, optional
574574
Group path within store.
575-
chunk_store : Store or string, optional
575+
chunk_store : Store or str, optional
576576
Store or path to directory in file system or name of zip file.
577577
storage_options : dict
578578
If using an fsspec URL to create the store, these will be passed to
@@ -664,22 +664,22 @@ async def create(
664664
False, will be set to `shape`, i.e., single chunk for the whole array.
665665
If an int, the chunk size in each dimension will be given by the value
666666
of `chunks`. Default is True.
667-
dtype : string or dtype, optional
667+
dtype : str or dtype, optional
668668
NumPy dtype.
669669
compressor : Codec, optional
670670
Primary compressor.
671671
fill_value : object
672672
Default value to use for uninitialized portions of the array.
673673
order : {'C', 'F'}, optional
674674
Memory layout to be used within each chunk.
675-
store : Store or string
675+
store : Store or str
676676
Store or path to directory in file system or name of zip file.
677677
synchronizer : object, optional
678678
Array synchronizer.
679679
overwrite : bool, optional
680680
If True, delete all pre-existing data in `store` at `path` before
681681
creating the array.
682-
path : string, optional
682+
path : str, optional
683683
Path under which array is stored.
684684
chunk_store : MutableMapping, optional
685685
Separate storage for chunks. If not provided, `store` will be used
@@ -937,11 +937,11 @@ async def open_array(
937937
938938
Parameters
939939
----------
940-
store : Store or string
940+
store : Store or str
941941
Store or path to directory in file system or name of zip file.
942942
zarr_format : {2, 3, None}, optional
943943
The zarr format to use when saving.
944-
path : string, optional
944+
path : str, optional
945945
Path in store to array.
946946
storage_options : dict
947947
If using an fsspec URL to create the store, these will be passed to

src/zarr/core/array.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,11 +1288,11 @@ def get_basic_selection(
12881288
array. May be any combination of int and/or slice or ellipsis for multidimensional arrays.
12891289
out : NDBuffer, optional
12901290
If given, load the selected data directly into this buffer.
1291+
prototype : BufferPrototype, optional
1292+
The prototype of the buffer to use for the output data. If not provided, the default buffer prototype is used.
12911293
fields : str or sequence of str, optional
12921294
For arrays with a structured dtype, one or more fields can be specified to
12931295
extract data for.
1294-
prototype : BufferPrototype, optional
1295-
The prototype of the buffer to use for the output data. If not provided, the default buffer prototype is used.
12961296
12971297
Returns
12981298
-------
@@ -2284,6 +2284,17 @@ def resize(self, new_shape: ChunkCoords) -> Array:
22842284
This method does not modify the original Array object. Instead, it returns a new Array
22852285
with the specified shape.
22862286
2287+
Notes
2288+
-----
2289+
When resizing an array, the data are not rearranged in any way.
2290+
2291+
If one or more dimensions are shrunk, any chunks falling outside the
2292+
new array shape will be deleted from the underlying store.
2293+
However, it is noteworthy that the chunks partially falling inside the new array
2294+
(i.e. boundary chunks) will remain intact, and therefore,
2295+
the data falling outside the new array but inside the boundary chunks
2296+
would be restored by a subsequent resize operation that grows the array size.
2297+
22872298
Examples
22882299
--------
22892300
>>> import zarr
@@ -2301,17 +2312,6 @@ def resize(self, new_shape: ChunkCoords) -> Array:
23012312
(20000, 1000)
23022313
>>> z2.shape
23032314
(50, 50)
2304-
2305-
Notes
2306-
-----
2307-
When resizing an array, the data are not rearranged in any way.
2308-
2309-
If one or more dimensions are shrunk, any chunks falling outside the
2310-
new array shape will be deleted from the underlying store.
2311-
However, it is noteworthy that the chunks partially falling inside the new array
2312-
(i.e. boundary chunks) will remain intact, and therefore,
2313-
the data falling outside the new array but inside the boundary chunks
2314-
would be restored by a subsequent resize operation that grows the array size.
23152315
"""
23162316
return type(self)(
23172317
sync(

0 commit comments

Comments
 (0)