Skip to content

Commit

Permalink
Document Field instance reuse workaround (#1730)
Browse files Browse the repository at this point in the history
* Document Field instance reuse workaround

Fixes: #1680

Signed-off-by: LundyBernard <lundy.bernard@gmail.com>

* Update dataframe_models.md

---------

Signed-off-by: LundyBernard <lundy.bernard@gmail.com>
Co-authored-by: Niels Bantilan <niels.bantilan@gmail.com>
  • Loading branch information
lundybernard and cosmicBboy authored Jul 8, 2024
1 parent 61ad398 commit 3f5e43e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/source/dataframe_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ class InputSchema(pa.DataFrameModel):
day: int = pa.Field(ge=0, le=365, coerce=True)
```

### Reusing Field objects

To define reuseable `Field` definitions, you need to use `functools.partial`.
This makes sure that each field attribute is bound to a unique `Field` instance.

```{code-cell} python
from functools import partial
from pandera import DataFrameModel, Field
NormalizedField = partial(Field, ge=0, le=1)
class InputSchema(DataFrameModel):
xnorm: float = NormalizedField()
ynorm: float = NormalizedField()
```

## Validate on Initialization

*new in 0.8.0*
Expand Down

0 comments on commit 3f5e43e

Please sign in to comment.