pandera.api.pandas.model.DataFrameModelΒΆ
- class pandera.api.pandas.model.DataFrameModel(*args, **kwargs)[source]ΒΆ
Model of a pandas
DataFrameSchema
.new in 0.5.0
See the User Guide for more.
Validate a DataFrame based on the schema specification.
- Parameters:
check_obj (pd.DataFrame) β the dataframe to be validated.
head β validate the first n rows. Rows overlapping with tail or sample are de-duplicated.
tail β validate the last n rows. Rows overlapping with head or sample are de-duplicated.
sample β validate a random sample of n rows. Rows overlapping with head or tail are de-duplicated.
random_state β random seed for the
sample
argument.lazy β if True, lazily evaluates dataframe against all validation checks and raises a
SchemaErrors
. Otherwise, raiseSchemaError
as soon as one occurs.inplace β if True, applies coercion to the object of validation, otherwise creates a copy of the data.
- Returns:
validated
DataFrame
- Raises:
SchemaError β when
DataFrame
violates built-in or custom checks.
Methods
- classmethod empty(*_args)[source]ΒΆ
Create an empty DataFrame with the schema of this model.
- Return type:
DataFrame
[Self
]
- classmethod to_json_schema()[source]ΒΆ
Serialize schema metadata into json-schema format.
- Parameters:
dataframe_schema β schema to write to json-schema format.
Note
This function is currently does not fully specify a pandera schema, and is primarily used internally to render OpenAPI docs via the FastAPI integration.
- classmethod validate(check_obj, head=None, tail=None, sample=None, random_state=None, lazy=False, inplace=False)[source]ΒΆ
Validate a DataFrame based on the schema specification.
- Parameters:
check_obj (pd.DataFrame) β the dataframe to be validated.
head (
Optional
[int
]) β validate the first n rows. Rows overlapping with tail or sample are de-duplicated.tail (
Optional
[int
]) β validate the last n rows. Rows overlapping with head or sample are de-duplicated.sample (
Optional
[int
]) β validate a random sample of n rows. Rows overlapping with head or tail are de-duplicated.random_state (
Optional
[int
]) β random seed for thesample
argument.lazy (
bool
) β if True, lazily evaluates dataframe against all validation checks and raises aSchemaErrors
. Otherwise, raiseSchemaError
as soon as one occurs.inplace (
bool
) β if True, applies coercion to the object of validation, otherwise creates a copy of the data.
- Return type:
DataFrame
[Self
]- Returns:
validated
DataFrame
- Raises:
SchemaError β when
DataFrame
violates built-in or custom checks.