You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/usage.md
+11-5Lines changed: 11 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,9 +48,11 @@ def get_all_cars():
48
48
In case one of the listed columns is missing from the DataFrame, a helpful assertion error is thrown:
49
49
50
50
```python
51
-
AssertionError("Column Price missing from DataFrame. Got columns: ['Brand']")
51
+
AssertionError("Missing columns: ['Price'] in function 'get_all_cars' return value. Got columns: ['Brand']")
52
52
```
53
53
54
+
The error message clearly indicates that this is a **return value** validation failure in the function `get_all_cars`.
55
+
54
56
## Combined Validation
55
57
56
58
To check both input and output, just use both annotations on the same function:
@@ -63,6 +65,10 @@ def filter_cars(car_df):
63
65
return filtered_cars_df
64
66
```
65
67
68
+
Note that error messages will clearly distinguish between input and output validation failures:
69
+
- Input validation: `"Missing columns: ['Price'] in function 'filter_cars' parameter 'car_df'. Got columns: ['Brand']"`
70
+
- Output validation: `"Missing columns: ['Price'] in function 'filter_cars' return value. Got columns: ['Brand']"`
71
+
66
72
## Column Pattern Matching with Regex
67
73
68
74
You can use regex patterns to match column names that follow a specific pattern. This is useful when working with dynamic column names or when dealing with many similar columns.
@@ -83,7 +89,7 @@ In this example:
83
89
If no columns match a regex pattern, an error is raised:
This will not only check that the specified columns are found from the DataFrame but also that their `dtype` is the expected. In case of a wrong `dtype`, an error message similar to following will explain the mismatch:
106
112
107
113
```
108
-
AssertionError("Column Price has wrong dtype. Was int64, expected float64")
114
+
AssertionError("Column Price in function 'process_cars' parameter 'car_df' has wrong dtype. Was int64, expected float64")
109
115
```
110
116
111
117
### Combining Regex Patterns with Data Type Validation
@@ -126,7 +132,7 @@ In this example:
126
132
If a column matches the regex pattern but has the wrong dtype, an error is raised:
127
133
128
134
```
129
-
AssertionError: Column Price_2 has wrong dtype. Was float64, expected int64
135
+
AssertionError: Column Price_2 in function 'process_data' parameter 'df' has wrong dtype. Was float64, expected int64
130
136
```
131
137
132
138
## Strict Mode
@@ -142,7 +148,7 @@ def process_cars(car_df):
142
148
will, when `car_df` contains columns `["Brand", "Price"]` raise an error:
0 commit comments