fiftyone.core.odm.mixins¶
Mixins and helpers for dataset backing documents.
Classes:
Mixin interface for |
|
Mixin for |
Functions:
|
Gets the default fields present on all instances of the given |
|
Validates that a given field or field description matches the type of the existing field. |
-
fiftyone.core.odm.mixins.
get_default_fields
(cls, include_private=False, use_db_fields=False)¶ Gets the default fields present on all instances of the given
DatasetMixin
class.- Parameters
cls – the
DatasetMixin
classinclude_private (False) – whether to include fields starting with
_
use_db_fields (False) – whether to return database fields rather than user-facing fields, when applicable
- Returns
a tuple of field names
-
fiftyone.core.odm.mixins.
validate_fields_match
(field_name, field_or_kwargs, existing_field_or_kwargs)¶ Validates that a given field or field description matches the type of the existing field.
- Parameters
field_name – the name of the field
field_or_kwargs – a
fiftyone.core.fields.Field
instance or a dict of keyword arguments describing itexisting_field_or_kwargs – a
fiftyone.core.fields.Field
instance or dict of keyword arguments defining the reference field type
- Raises
ValueError – if the proposed field does not match the reference field
-
class
fiftyone.core.odm.mixins.
DatasetMixin
¶ Bases:
object
Mixin interface for
fiftyone.core.odm.document.Document
subclasses that are backed by a dataset.Methods:
add_field
(field_name, ftype[, …])Adds a new field to the document.
add_implied_field
(field_name, value)Adds the field to the document, if necessary, inferring the field type from the provided value.
clear_field
(field_name)get_field
(field_name)get_field_schema
([ftype, embedded_doc_type, …])Returns a schema dictionary describing the fields of this document.
has_field
(field_name)merge_field_schema
(schema[, expand_schema])Merges the field schema into this document.
set_field
(field_name, value[, create])Attributes:
-
property
collection_name
¶
-
property
field_names
¶
-
has_field
(field_name)¶
-
get_field
(field_name)¶
-
set_field
(field_name, value, create=False)¶
-
clear_field
(field_name)¶
-
classmethod
get_field_schema
(ftype=None, embedded_doc_type=None, include_private=False)¶ Returns a schema dictionary describing the fields of this document.
If the document belongs to a dataset, the schema will apply to all documents in the collection.
- Parameters
ftype (None) – an optional field type to which to restrict the returned schema. Must be a subclass of
fiftyone.core.fields.Field
embedded_doc_type (None) – an optional embedded document type to which to restrict the returned schema. Must be a subclass of
fiftyone.core.odm.BaseEmbeddedDocument
include_private (False) – whether to include fields that start with
_
in the returned schema
- Returns
a dictionary mapping field names to field types
-
classmethod
merge_field_schema
(schema, expand_schema=True)¶ Merges the field schema into this document.
- Parameters
schema – a dictionary mapping field names to
fiftyone.core.fields.Field
instancesexpand_schema (True) – whether to add new fields to the schema
- Raises
ValueError – if a field in the schema is not compliant with an existing field of the same name or a new field is found but
expand_schema == False
-
classmethod
add_field
(field_name, ftype, embedded_doc_type=None, subfield=None, fields=None, **kwargs)¶ Adds a new field to the document.
- Parameters
field_name – the field name
ftype – the field type to create. Must be a subclass of
fiftyone.core.fields.Field
embedded_doc_type (None) – the
fiftyone.core.odm.BaseEmbeddedDocument
type of the field. Only applicable whenftype
isfiftyone.core.fields.EmbeddedDocumentField
subfield (None) – the
fiftyone.core.fields.Field
type of the contained field. Only applicable whenftype
isfiftyone.core.fields.ListField
orfiftyone.core.fields.DictField
fields (None) – the field definitions of the
fiftyone.core.fields.EmbeddedDocumentField
Only applicable whenftype
isfiftyone.core.fields.EmbeddedDocumentField
-
classmethod
add_implied_field
(field_name, value)¶ Adds the field to the document, if necessary, inferring the field type from the provided value.
- Parameters
field_name – the field name
value – the field value
-
property
-
class
fiftyone.core.odm.mixins.
NoDatasetMixin
¶ Bases:
object
Mixin for
fiftyone.core.odm.document.SerializableDocument
subtypes that are not backed by a dataset.Methods:
clear_field
(field_name)delete
()from_dict
(d[, extended])get_field
(field_name)has_field
(field_name)reload
()save
()set_field
(field_name, value[, create])to_dict
([extended])Attributes:
-
property
field_names
¶
-
property
collection_name
¶
-
property
in_db
¶
-
has_field
(field_name)¶
-
get_field
(field_name)¶
-
set_field
(field_name, value, create=False)¶
-
clear_field
(field_name)¶
-
to_dict
(extended=False)¶
-
classmethod
from_dict
(d, extended=False)¶
-
save
()¶
-
reload
()¶
-
delete
()¶
-
property