-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from p2p-ld/dtype-union
[dtype] Support Unions
- Loading branch information
Showing
23 changed files
with
443 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# dtype | ||
|
||
```{eval-rst} | ||
.. automodule:: numpydantic.validation.dtype | ||
:members: | ||
:undoc-members: | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# validation | ||
|
||
```{toctree} | ||
dtype | ||
shape | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# shape | ||
|
||
```{eval-rst} | ||
.. automodule:: numpydantic.shape | ||
.. automodule:: numpydantic.validation.shape | ||
:members: | ||
:undoc-members: | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# dtype | ||
|
||
```{todo} | ||
This section is under construction as of 1.6.1 | ||
Much of the details of dtypes are covered in [syntax](./syntax.md) | ||
and in {mod}`numpydantic.dtype` , but this section will specifically | ||
address how dtypes are handled both generically and by interfaces | ||
as we expand custom dtype handling <3. | ||
For details of support and implementation until the docs have time for some love, | ||
please see the tests, which are the source of truth for the functionality | ||
of the library for now and forever. | ||
``` | ||
|
||
Recall the general syntax: | ||
|
||
``` | ||
NDArray[Shape, dtype] | ||
``` | ||
|
||
These are the docs for what can do in `dtype`. | ||
|
||
## Scalar Dtypes | ||
|
||
Python builtin types and numpy types should be handled transparently, | ||
with some exception for complex numbers and objects (described below). | ||
|
||
### Numbers | ||
|
||
#### Complex numbers | ||
|
||
```{todo} | ||
Document limitations for complex numbers and strategies for serialization/validation | ||
``` | ||
|
||
### Datetimes | ||
|
||
```{todo} | ||
Datetimes are supported by every interface except :class:`.VideoInterface` , | ||
with the caveat that HDF5 loses timezone information, and thus all timestamps should | ||
be re-encoded to UTC before saving/loading. | ||
More generic datetime support is TODO. | ||
``` | ||
|
||
### Objects | ||
|
||
```{todo} | ||
Generic objects are supported by all interfaces except | ||
:class:`.VideoInterface` , :class;`.HDF5Interface` , and :class:`.ZarrInterface` . | ||
this might be expected, but there is also hope, TODO fill in serialization plans. | ||
``` | ||
|
||
### Strings | ||
|
||
```{todo} | ||
Strings are supported by all interfaces except :class:`.VideoInterface` . | ||
TODO is fill in the subtleties of how this works | ||
``` | ||
|
||
## Generic Dtypes | ||
|
||
```{todo} | ||
For now these are handled as tuples of dtypes, see the source of | ||
{ref}`numpydantic.dtype.Float` . They should either be handled as Unions | ||
or as a more prescribed meta-type. | ||
For now, use `int` and `float` to refer to the general concepts of | ||
"any int" or "any float" even if this is a bit mismatched from the numpy usage. | ||
``` | ||
|
||
## Extended Python Typing Universe | ||
|
||
### Union Types | ||
|
||
Union types can be used as expected. | ||
|
||
Union types are tested recursively -- if any item within a ``Union`` matches | ||
the expected dtype at a given level of recursion, the dtype test passes. | ||
|
||
```python | ||
class MyModel(BaseModel): | ||
array: NDArray[Any, int | float] | ||
``` | ||
|
||
## Compound Dtypes | ||
|
||
```{todo} | ||
Compound dtypes are currently unsupported, | ||
though the HDF5 interface supports indexing into compound dtypes | ||
as separable dimensions/arrays using the third "field" parameter in | ||
{class}`.hdf5.H5ArrayPath` . | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "numpydantic" | ||
version = "1.6.0" | ||
version = "1.6.1" | ||
description = "Type and shape validation and serialization for arbitrary array types in pydantic models" | ||
authors = [ | ||
{name = "sneakers-the-rat", email = "[email protected]"}, | ||
|
@@ -126,7 +126,7 @@ markers = [ | |
] | ||
|
||
[tool.ruff] | ||
target-version = "py311" | ||
target-version = "py39" | ||
include = ["src/numpydantic/**/*.py", "pyproject.toml"] | ||
exclude = ["tests"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.