Created
January 27, 2020 16:26
-
-
Save cosmic-cortex/928f746e9d895889ce19f6a3dbe5a856 to your computer and use it in GitHub Desktop.
Additional validation for the PredictRequest model
This file contains hidden or 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
from pydantic import BaseModel, ValidationError, validator | |
from .ml.model import n_features | |
class PredictRequest(BaseModel): | |
data: List[List[float]] | |
@validator("data") | |
def check_dimensionality(cls, v): | |
for point in v: | |
if len(point) != n_features: | |
raise ValueError(f"Each data point must contain {n_features} features") | |
return v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment