1.2.0 - shape ranges

update docs, bump version
This commit is contained in:
sneakers-the-rat 2024-06-14 22:56:28 -07:00
parent 07ab3d1b76
commit f482f07be9
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
6 changed files with 39 additions and 1 deletions

7
docs/api/shape.md Normal file
View file

@ -0,0 +1,7 @@
# shape
```{eval-rst}
.. automodule:: numpydantic.shape
:members:
:undoc-members:
```

View file

@ -2,6 +2,10 @@
## 1.*
### 1.2.0 - 24-06-13 - Shape ranges
- Add ability to specify shapes as ranges - see [shape ranges](shape-ranges)
### 1.1.0 - 24-05-24 - Instance Checking
https://github.com/p2p-ld/numpydantic/pull/1

View file

@ -491,6 +491,7 @@ api/maps
api/meta
api/monkeypatch
api/schema
api/shape
api/types
```

View file

@ -61,6 +61,24 @@ For a 2-dimensional, 3 x any-shaped array:
Shape["3, *"]
```
(shape-ranges)=
### Ranges
Dimension sizes can also be specified as ranges[^ranges].
Ranges must have no whitespace, and may use integers or wildcards.
Range specifications are **inclusive** on both ends.
For an array whose...
- First dimension can be of length 2, 3, or 4
- Second dimension is 2 or greater
- Third dimension is 4 or less
```python
Shape["2-4, 2-*, *-4"]
```
[^ranges]: This is an extension to nptyping's syntax, and so using `nptyping.Shape` is unsupported - use {class}`numpydantic.Shape`
### Labels
Dimensions can be given labels, and in future versions these labels will be

View file

@ -1,6 +1,6 @@
[project]
name = "numpydantic"
version = "1.1.0"
version = "1.2.0"
description = "Type and shape validation and serialization for numpy arrays in pydantic models"
authors = [
{name = "sneakers-the-rat", email = "sneakers-the-rat@protonmail.com"},

View file

@ -58,6 +58,14 @@ class ShapeMeta(ContainerMeta, implementation="Shape"):
dim_string_without_labels = remove_labels(dim_strings)
return {"prepared_args": dim_string_without_labels}
def __setattr__(cls, key: str, value: Any) -> None: # pragma: no cover
"""just for documentation generation - allow __annotations__"""
if key not in ("_abc_impl", "__abstractmethods__", "__annotations__"):
raise NPTypingError(f"Cannot set values to nptyping.{cls.__name__}.")
else:
object.__setattr__(cls, key, value)
class Shape(NPTypingType, ABC, metaclass=ShapeMeta):
"""