Last active
April 29, 2023 15:06
-
-
Save freegor/0bdb6aadf059f8346ab8bc85199879ff to your computer and use it in GitHub Desktop.
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
import pandas | |
from pydantic import BaseModel | |
class CustomBaseModel(BaseModel): | |
class Config: | |
arbitrary_types_allowed = True | |
json_encoders = { | |
pandas.DataFrame: lambda v: serialize_with_pyarrow(v) | |
} | |
class Dataset(CustomBaseModel): | |
id: str | |
name: constr(max_length=128) | |
dataframe: pandas.DataFrame | |
@validator('id') | |
def is_uuid4_string(cls, value): | |
try: | |
UUID(value, version=4) | |
except ValueError as ve: | |
raise ValueError('The id value is not uuid4') from ve | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment