Data types supported by DataChain must be of type
DataType. DataType includes most Python types
supported in Pydantic fields, as well as any class that
inherits from Pydantic BaseModel.
Pydantic models can be used to group and nest multiple fields together into a single
type object. Any Pydantic model must be
registered so that the chain knows the
expected schema of the model. Alternatively, models may inherit from
DataModel, which is a lightweight wrapper
around Pydantic's BaseModel that automatically handles registering the model.
@staticmethoddefregister(models:Union[DataType,Sequence[DataType]]):"""For registering classes manually. It accepts a single class or a sequence of classes."""ifnotisinstance(models,Sequence):models=[models]forvalinmodels:ModelStore.register(val)
defis_chain_type(t:type)->bool:"""Return true if type is supported by `DataChain`."""ifModelStore.is_pydantic(t):returnTrueifany(tisftortisget_args(ft)[0]forftinget_args(StandardType)):returnTrueorig=get_origin(t)args=get_args(t)iforigislistandlen(args)==1:returnis_chain_type(get_args(t)[0])iforigisUnionandlen(args)==2and(type(None)inargs):returnis_chain_type(args[0])returnFalse