Skip to content

Add some numpydoc validation checks #2316

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 1 commit into from
Oct 9, 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: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ repos:
hooks:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/numpy/numpydoc
rev: v1.8.0
hooks:
- id: numpydoc-validation
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,7 @@ ignore = [
"PC111", # fix Python code in documentation - enable later
"PC180", # for JavaScript - not interested
]

[tool.numpydoc_validation]
# See https://numpydoc.readthedocs.io/en/latest/validation.html#built-in-validation-checks for list of checks
checks = ["GL06", "GL07", "GL10", "PR03", "PR05", "PR06"]
30 changes: 15 additions & 15 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ async def load(

Parameters
----------
store : Store or string
store : Store or str
Store or path to directory in file system or name of zip file.
path : str or None, optional
The path within the store from which to load.
Expand Down Expand Up @@ -203,7 +203,7 @@ async def open(

Parameters
----------
store : Store or string, optional
store : Store or str, optional
Store or path to directory in file system or name of zip file.
mode : {'r', 'r+', 'a', 'w', 'w-'}, optional
Persistence mode: 'r' means read only (must exist); 'r+' means
Expand Down Expand Up @@ -267,7 +267,7 @@ async def save(

Parameters
----------
store : Store or string
store : Store or str
Store or path to directory in file system or name of zip file.
args : ndarray
NumPy arrays with data to save.
Expand Down Expand Up @@ -303,7 +303,7 @@ async def save_array(

Parameters
----------
store : Store or string
store : Store or str
Store or path to directory in file system or name of zip file.
arr : ndarray
NumPy array with data to save.
Expand Down Expand Up @@ -351,7 +351,7 @@ async def save_group(

Parameters
----------
store : Store or string
store : Store or str
Store or path to directory in file system or name of zip file.
args : ndarray
NumPy arrays with data to save.
Expand Down Expand Up @@ -467,7 +467,7 @@ async def group(

Parameters
----------
store : Store or string, optional
store : Store or str, optional
Store or path to directory in file system.
overwrite : bool, optional
If True, delete any pre-existing data in `store` at `path` before
Expand All @@ -481,7 +481,7 @@ async def group(
to all attribute read operations.
synchronizer : object, optional
Array synchronizer.
path : string, optional
path : str, optional
Group path within store.
meta_array : array-like, optional
An array instance to use for determining arrays to create and return
Expand Down Expand Up @@ -547,7 +547,7 @@ async def open_group(

Parameters
----------
store : Store, string, or mapping, optional
store : Store, str, or mapping, optional
Store or path to directory in file system or name of zip file.

Strings are interpreted as paths on the local file system
Expand All @@ -570,9 +570,9 @@ async def open_group(
to all attribute read operations.
synchronizer : object, optional
Array synchronizer.
path : string, optional
path : str, optional
Group path within store.
chunk_store : Store or string, optional
chunk_store : Store or str, optional
Store or path to directory in file system or name of zip file.
storage_options : dict
If using an fsspec URL to create the store, these will be passed to
Expand Down Expand Up @@ -664,22 +664,22 @@ async def create(
False, will be set to `shape`, i.e., single chunk for the whole array.
If an int, the chunk size in each dimension will be given by the value
of `chunks`. Default is True.
dtype : string or dtype, optional
dtype : str or dtype, optional
NumPy dtype.
compressor : Codec, optional
Primary compressor.
fill_value : object
Default value to use for uninitialized portions of the array.
order : {'C', 'F'}, optional
Memory layout to be used within each chunk.
store : Store or string
store : Store or str
Store or path to directory in file system or name of zip file.
synchronizer : object, optional
Array synchronizer.
overwrite : bool, optional
If True, delete all pre-existing data in `store` at `path` before
creating the array.
path : string, optional
path : str, optional
Path under which array is stored.
chunk_store : MutableMapping, optional
Separate storage for chunks. If not provided, `store` will be used
Expand Down Expand Up @@ -937,11 +937,11 @@ async def open_array(

Parameters
----------
store : Store or string
store : Store or str
Store or path to directory in file system or name of zip file.
zarr_format : {2, 3, None}, optional
The zarr format to use when saving.
path : string, optional
path : str, optional
Path in store to array.
storage_options : dict
If using an fsspec URL to create the store, these will be passed to
Expand Down
26 changes: 13 additions & 13 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,11 +1288,11 @@ def get_basic_selection(
array. May be any combination of int and/or slice or ellipsis for multidimensional arrays.
out : NDBuffer, optional
If given, load the selected data directly into this buffer.
prototype : BufferPrototype, optional
The prototype of the buffer to use for the output data. If not provided, the default buffer prototype is used.
fields : str or sequence of str, optional
For arrays with a structured dtype, one or more fields can be specified to
extract data for.
prototype : BufferPrototype, optional
The prototype of the buffer to use for the output data. If not provided, the default buffer prototype is used.

Returns
-------
Expand Down Expand Up @@ -2284,6 +2284,17 @@ def resize(self, new_shape: ChunkCoords) -> Array:
This method does not modify the original Array object. Instead, it returns a new Array
with the specified shape.

Notes
-----
When resizing an array, the data are not rearranged in any way.

If one or more dimensions are shrunk, any chunks falling outside the
new array shape will be deleted from the underlying store.
However, it is noteworthy that the chunks partially falling inside the new array
(i.e. boundary chunks) will remain intact, and therefore,
the data falling outside the new array but inside the boundary chunks
would be restored by a subsequent resize operation that grows the array size.

Examples
--------
>>> import zarr
Expand All @@ -2301,17 +2312,6 @@ def resize(self, new_shape: ChunkCoords) -> Array:
(20000, 1000)
>>> z2.shape
(50, 50)

Notes
-----
When resizing an array, the data are not rearranged in any way.

If one or more dimensions are shrunk, any chunks falling outside the
new array shape will be deleted from the underlying store.
However, it is noteworthy that the chunks partially falling inside the new array
(i.e. boundary chunks) will remain intact, and therefore,
the data falling outside the new array but inside the boundary chunks
would be restored by a subsequent resize operation that grows the array size.
"""
return type(self)(
sync(
Expand Down
28 changes: 14 additions & 14 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ async def get(

Parameters
----------
key : string
key : str
Group member name.
default : object
Default value to return if key is not found (default: None).
Expand Down Expand Up @@ -396,7 +396,7 @@ async def require_group(self, name: str, overwrite: bool = False) -> AsyncGroup:

Parameters
----------
name : string
name : str
Group name.
overwrite : bool, optional
Overwrite any existing group with given `name` if present.
Expand Down Expand Up @@ -525,7 +525,7 @@ async def create_dataset(self, name: str, **kwargs: Any) -> AsyncArray:

Parameters
----------
name : string
name : str
Array name.
kwargs : dict
Additional arguments passed to :func:`zarr.AsyncGroup.create_array`.
Expand Down Expand Up @@ -558,11 +558,11 @@ async def require_dataset(

Parameters
----------
name : string
name : str
Array name.
shape : int or tuple of ints
Array shape.
dtype : string or dtype, optional
dtype : str or dtype, optional
NumPy dtype.
exact : bool, optional
If True, require `dtype` to match exactly. If false, require
Expand Down Expand Up @@ -592,11 +592,11 @@ async def require_array(

Parameters
----------
name : string
name : str
Array name.
shape : int or tuple of ints
Array shape.
dtype : string or dtype, optional
dtype : str or dtype, optional
NumPy dtype.
exact : bool, optional
If True, require `dtype` to match exactly. If false, require
Expand Down Expand Up @@ -857,7 +857,7 @@ def get(self, path: str, default: DefaultT | None = None) -> Array | Group | Def

Parameters
----------
key : string
key : str
Group member name.
default : object
Default value to return if key is not found (default: None).
Expand Down Expand Up @@ -1003,7 +1003,7 @@ def require_group(self, name: str, **kwargs: Any) -> Group:

Parameters
----------
name : string
name : str
Group name.
overwrite : bool, optional
Overwrite any existing group with given `name` if present.
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def create_dataset(self, name: str, **kwargs: Any) -> Array:

Parameters
----------
name : string
name : str
Array name.
kwargs : dict
Additional arguments passed to :func:`zarr.Group.create_array`
Expand All @@ -1150,11 +1150,11 @@ def require_dataset(self, name: str, **kwargs: Any) -> Array:

Parameters
----------
name : string
name : str
Array name.
shape : int or tuple of ints
Array shape.
dtype : string or dtype, optional
dtype : str or dtype, optional
NumPy dtype.
exact : bool, optional
If True, require `dtype` to match exactly. If false, require
Expand All @@ -1177,11 +1177,11 @@ def require_array(self, name: str, **kwargs: Any) -> Array:

Parameters
----------
name : string
name : str
Array name.
shape : int or tuple of ints
Array shape.
dtype : string or dtype, optional
dtype : str or dtype, optional
NumPy dtype.
exact : bool, optional
If True, require `dtype` to match exactly. If false, require
Expand Down
12 changes: 6 additions & 6 deletions src/zarr/storage/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ class ZipStore(Store):

Parameters
----------
path : string
path : str
Location of file.
compression : integer, optional
mode : str, optional
One of 'r' to read an existing file, 'w' to truncate and write a new
file, 'a' to append to an existing file, or 'x' to exclusively create
and write a new file.
compression : int, optional
Compression method to use when writing to the archive.
allowZip64 : bool, optional
If True (the default) will create ZIP files that use the ZIP64
extensions when the zipfile is larger than 2 GiB. If False
will raise an exception when the ZIP file would require ZIP64
extensions.
mode : string, optional
One of 'r' to read an existing file, 'w' to truncate and write a new
file, 'a' to append to an existing file, or 'x' to exclusively create
and write a new file.
"""

supports_writes: bool = True
Expand Down