ValidBboxAnnotationsCOCO#
- class ethology.validators.annotations.ValidBboxAnnotationsCOCO(*args, **kwargs)[source]#
Bases:
DataFrameModelClass for COCO-exportable bounding box annotations dataframes.
The validation checks the required columns exist and their types are correct. It additionally checks that the index and the
annotation_idcolumn are equal.- idx#
Index of the dataframe. Should be greater than or equal to 0 and equal to the
annotation_idcolumn.- Type:
- segmentation#
Bounding box segmentation masks as list of lists of coordinates.
- Raises:
pandera.errors.SchemaError – If the dataframe does not match the schema.
Notes
See COCO format documentation for more details.
Methods
build_schema_(**kwargs)Check that the index and the
annotation_idcolumn are equal.empty(*_args)Create an empty DataFrame with the schema of this model.
example(**kwargs)Generate an example of this data model specification.
from_json(source)Load a schema from JSON.
from_yaml(yaml_schema)Load a schema from YAML.
Provide metadata for columns and schema level
Map COCO-exportable dataframe columns to COCO fields.
pydantic_validate(schema_model)Verify that the input is a compatible dataframe model.
strategy(**kwargs)Create a data synthesis strategy.
to_json([target])Convert this model's schema to JSON.
Serialize schema metadata into json-schema format.
Create
DataFrameSchemafrom theDataFrameModel.to_yaml([stream])Convert this model's schema to YAML.
validate(check_obj[, head, tail, sample, ...])Validate a DataFrame based on the schema specification.
- class Config#
Bases:
BaseConfig- dtype: Union[str, type, DataType, ExtensionDtype, dtype, None] = None#
datatype of the dataframe. This overrides the data types specified in any of the fields.
- from_format: Union[Literal[Formats.csv], Literal[Formats.dict], Literal[Formats.json], Literal[Formats.feather], Literal[Formats.parquet], Literal[Formats.pickle], Literal[Formats.json_normalize], Callable, None] = None#
data format before validation. This option only applies to schemas used in the context of the pandera type constructor
pa.typing.DataFrame[Schema](data). If None, assumes a data structure compatible with thepandas.DataFrameconstructor.
- from_format_kwargs: dict[str, Any] | None = None#
a dictionary keyword arguments to pass into the reader function that converts the object of type
from_formatto a pandera-validate-able data structure. The reader function is implemented in the pandera.typing generic types via thefrom_formatandto_formatmethods.
- multiindex_strict: Union[bool, Literal['filter']] = False#
make sure all specified columns are in validated MultiIndex - if
"filter", removes indexes not specified in the schema
- multiindex_unique = None#
make sure the MultiIndex is unique along the list of columns
- on_missing_columns: str | None = None#
action to take when an optional column is missing from the dataframe.
None(default) passes silently,"warn"emits aSchemaWarning. Overridable per field viaField(on_missing=...).
- strict: Union[bool, Literal['filter']] = False#
make sure all specified columns are in the validated dataframe - if
"filter", removes columns not specified in the schema
- to_format: Union[Literal[Formats.csv], Literal[Formats.dict], Literal[Formats.json], Literal[Formats.feather], Literal[Formats.parquet], Literal[Formats.pickle], Literal[Formats.json_normalize], Callable, None] = None#
data format to serialize into after validation. This option only applies to schemas used in the context of the pandera type constructor
pa.typing.DataFrame[Schema](data). If None, returns a dataframe.
- to_format_buffer: Union[str, Callable, None] = None#
Buffer to be provided when to_format is a custom callable. See docs for example of how to implement an example of a to format function.
- classmethod check_idx_and_annotation_id(df)[source]#
Check that the index and the
annotation_idcolumn are equal.
- classmethod empty(*_args)#
Create an empty DataFrame with the schema of this model.
- classmethod example(**kwargs)#
Generate an example of this data model specification.
- Return type:
DataFrameBase[Self]
- classmethod from_json(source)#
Load a schema from JSON.
- Parameters:
source – str, Path, or file stream with JSON content.
- Returns:
the backend-specific schema object.
- classmethod from_yaml(yaml_schema)#
Load a schema from YAML.
- Parameters:
yaml_schema – str, Path, or file stream with YAML content.
- Returns:
the backend-specific schema object.
- classmethod get_metadata()#
Provide metadata for columns and schema level
- static map_df_columns_to_COCO_fields()[source]#
Map COCO-exportable dataframe columns to COCO fields.
- Returns:
A dictionary mapping each column in the COCO-exportable dataframe to the corresponding fields in the equivalent COCO file.
- Return type:
- classmethod pydantic_validate(schema_model)#
Verify that the input is a compatible dataframe model.
- Return type:
- classmethod strategy(**kwargs)#
Create a data synthesis strategy.
- classmethod to_json(target=None, **kwargs)#
Convert this model’s schema to JSON.
- classmethod to_json_schema()#
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 to_schema()#
Create
DataFrameSchemafrom theDataFrameModel.- Return type:
TSchema
- classmethod to_yaml(stream=None)#
Convert this model’s schema to YAML.
- classmethod validate(check_obj, head=None, tail=None, sample=None, random_state=None, lazy=False, inplace=False)#
Validate a DataFrame based on the schema specification.
- Parameters:
check_obj (
DataFrame) – the dataframe to be validated.head (
int|None) – validate the first n rows. Rows overlapping with tail or sample are de-duplicated.tail (
int|None) – validate the last n rows. Rows overlapping with head or sample are de-duplicated.sample (
int|None) – validate a random sample of n rows. Rows overlapping with head or tail are de-duplicated.random_state (
int|None) – random seed for thesampleargument.lazy (
bool) – if True, lazily evaluates dataframe against all validation checks and raises aSchemaErrors. Otherwise, raiseSchemaErroras soon as one occurs.inplace (
bool) – if True, applies coercion to the object of validation, otherwise creates a copy of the data.
- Return type:
- Returns:
validated
DataFrame- Raises:
SchemaError – when
DataFrameviolates built-in or custom checks.