I am currently trying to validate the input arguments of a function with pydantic. This works fine for the built-in datatypes, but not for types like pandas.DataFrame or numpy.array. Example:
@validate_arguments
def some_function(params: pd.DataFrame,
var_name: str
) -> dict:
# do something
return my_dict
When calling some_function the following error is shown:
RuntimeError: no validator found for <class 'pandas.core.frame.DataFrame'>, see `arbitrary_types_allowed` in Config`
My first idea was to define my own DataFrame type with something like this:
class MyDF(pd.DataFrame):
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, val):
return pd.DataFrame(val)
I am not sure, if this is the best practice. Does anyone have better ideas?