Skip to content

Commit f6e11e0

Browse files
committed
Add Validoopsie example
1 parent c8c7091 commit f6e11e0

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/blog/survey-validation-libs/index.qmd

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ look like rather than writing imperative validation logic. The schema acts as bo
8282
as a validation contract. Notice how multiple checks can be applied to a single column (here, the
8383
`age` column receives two checks), and the validation either succeeds completely or provides
8484
error information about what failed.
85+
8586
## 2. Patito: Pydantic-Style Data Models for DataFrames
8687

8788
Patito brings Pydantic's well-received model-based validation approach to DataFrame validation,
@@ -150,3 +151,46 @@ of validation logic from modular, testable components that can be combined in fl
150151
create complex validation workflows. Like Pointblank, Validoopsie had Polars support from the very
151152
first release (early-2025).
152153

154+
```{python}
155+
from validoopsie import Validate
156+
from narwhals.dtypes import Int64, Float64, String
157+
158+
# Composable validation checks using our standard dataset
159+
validation = (
160+
Validate(user_data)
161+
.ValuesValidation.ColumnValuesToBeBetween(
162+
column="user_id",
163+
min_value=0
164+
)
165+
.ValuesValidation.ColumnValuesToBeBetween(
166+
column="age",
167+
min_value=18,
168+
max_value=80
169+
)
170+
.StringValidation.PatternMatch(
171+
column="email",
172+
pattern=r"^[^@]+@[^@]+\.[^@]+$"
173+
)
174+
.ValuesValidation.ColumnValuesToBeBetween(
175+
column="score",
176+
min_value=0,
177+
max_value=100
178+
)
179+
.TypeValidation.TypeCheck(
180+
frame_schema_definition={
181+
"user_id": Int64,
182+
"age": Int64,
183+
"email": String,
184+
"score": Float64
185+
}
186+
)
187+
)
188+
189+
# Check if validation passed
190+
try:
191+
validation.validate()
192+
print("Validation successful!")
193+
except Exception as e:
194+
print(f"Validation failed: {e}")
195+
```
196+

0 commit comments

Comments
 (0)