Skip to content

Instantly share code, notes, and snippets.

@freegor
Last active April 29, 2023 15:06
Show Gist options
  • Save freegor/0bdb6aadf059f8346ab8bc85199879ff to your computer and use it in GitHub Desktop.
Save freegor/0bdb6aadf059f8346ab8bc85199879ff to your computer and use it in GitHub Desktop.
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