Skip to content

Commit

Permalink
Chore(README.md): Clarification for Pydantic support
Browse files Browse the repository at this point in the history
Changes made because of an alarming interpretation of the package on pydantic/pydantic-extra-types#31
  • Loading branch information
Can H. Tartanoglu committed Nov 19, 2023
1 parent c1536c7 commit fb13b5e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

Package that integrates NumPy Arrays into Pydantic!

- `NumpyModel` make it possible to dump and load `np.ndarray` within model fields alongside other fields that are not instances of `np.ndarray`!
- `pydantic_numpy.typing` provides many typings such as `NpNDArrayFp64`, `Np3DArrayFp64` (float64 that must be 3D)!
- `pydantic_numpy.typing` provides many typings such as `NpNDArrayFp64`, `Np3DArrayFp64` (float64 that must be 3D)! Works with both `pydantic.BaseModel` and `pydantic.dataclass`
- `NumpyModel` (derived from `pydantic.BaseModel`) make it possible to dump and load `np.ndarray` within model fields alongside other fields that are not instances of `np.ndarray`!

## Usage

For more examples see [test_ndarray.py](./tests/test_typing.py)

```python
import numpy as np
from pydantic import BaseModel

import pydantic_numpy.typing as pnd
from pydantic_numpy import np_array_pydantic_annotated_typing
from pydantic_numpy.model import NumpyModel, MultiArrayNumpyFile


class MyNumpyModel(NumpyModel):
class MyBaseModelDerivedModel(BaseModel):
any_array_dtype_and_dimension: pnd.NpNDArray

# Must be numpy float32 as dtype
Expand All @@ -27,7 +28,7 @@ class MyNumpyModel(NumpyModel):
must_be_1d_np_array: np_array_pydantic_annotated_typing(dimensions=1)


class MyDemoModel(NumpyModel):
class MyDemoNumpyModel(NumpyModel):
k: np_array_pydantic_annotated_typing(data_type=np.float32)


Expand Down

0 comments on commit fb13b5e

Please sign in to comment.