class documentation

Undocumented

Method __contains__ Undocumented
Method __copy__ Undocumented
Method __delattr__ Undocumented
Method __delitem__ Undocumented
Method __dir__ Undocumented
Method __eq__ Undocumented
Method __getattr__ Undocumented
Method __getitem__ Undocumented
Method __init__ Undocumented
Method __repr__ Undocumented
Method __setattr__ Undocumented
Method __setitem__ Undocumented
Method __str__ Undocumented
Method clear_field Clears the value of a field of the document.
Method copy Returns a deep copy of the document that has not been added to the database.
Method get_field Gets the value of a field of the document.
Method has_field Determines whether the document has the given field.
Method iter_fields Returns an iterator over the (name, value) pairs of the public fields of the document.
Method merge Merges the fields of the document into this document.
Method save Saves the document to the database.
Method set_field Sets the value of a field of the document.
Method to_dict Serializes the document to a JSON dictionary.
Method to_json Serializes the document to a JSON string.
Method to_mongo_dict Serializes the document to a BSON dictionary equivalent to the representation that would be stored in the database.
Method update_fields Sets the dictionary of fields on the document.
Property dataset The dataset to which this document belongs, or None if it has not been added to a dataset.
Property field_names An ordered tuple of the public field names of this document.
Property in_dataset Whether the document has been added to a dataset.
Method _get_field_names Returns an ordered tuple of field names of this document.
Method _iter_label_fields Undocumented
Method _parse_fields Undocumented
Method _save Undocumented
Instance Variable _dataset Undocumented
Instance Variable _doc Undocumented
Property _collection The fiftyone.core.collections.SampleCollection from which this document was taken, or None if it is not in a dataset.
Property _id The ObjectId of the document, or None if it has not been added to the database.
Property _in_db Whether the document has been inserted into the database.
def __contains__(self, name): (source)

Undocumented

def __copy__(self): (source)

Undocumented

def __delattr__(self, name): (source)

Undocumented

def __delitem__(self, field_name): (source)

Undocumented

def __dir__(self): (source)

Undocumented

def __eq__(self, other): (source)

Undocumented

def __getattr__(self, name): (source)

Undocumented

def __getitem__(self, field_name): (source)

Undocumented

def __init__(self, doc, dataset=None): (source)
def __setattr__(self, name, value): (source)

Undocumented

def __setitem__(self, field_name, value): (source)

Undocumented

def __str__(self): (source)

Undocumented

def clear_field(self, field_name): (source)

Clears the value of a field of the document.

Parameters
field_namethe name of the field to clear
Raises
AttributeErrorif the field does not exist
def copy(self, fields=None, omit_fields=None): (source)

Returns a deep copy of the document that has not been added to the database.

Parameters
fields:Nonean optional field or iterable of fields to which to restrict the copy. This can also be a dict mapping existing field names to new field names
omit_fields:Nonean optional field or iterable of fields to exclude from the copy
Returns
a Document
def get_field(self, field_name): (source)

Gets the value of a field of the document.

Parameters
field_namethe field name
Returns
the field value
Raises
AttributeErrorif the field does not exist
def has_field(self, field_name): (source)

Determines whether the document has the given field.

Parameters
field_namethe field name
Returns
True/False
def iter_fields(self, include_id=False, include_timestamps=False): (source)

Returns an iterator over the (name, value) pairs of the public fields of the document.

Parameters
include_id:Falsewhether to include the id field
include_timestamps:Falsewhether to include the created_at and last_modified_at fields
Returns
an iterator that emits (name, value) tuples
def merge(self, document, fields=None, omit_fields=None, merge_lists=True, overwrite=True, expand_schema=True, validate=True, dynamic=False): (source)

Merges the fields of the document into this document.

The behavior of this method is highly customizable. By default, all top-level fields from the provided document are merged in, overwriting any existing values for those fields, with the exception of list fields (e.g., tags) and label list fields (e.g., fiftyone.core.labels.Detections fields), in which case the elements of the lists themselves are merged. In the case of label list fields, labels with the same id in both documents are updated rather than duplicated.

To avoid confusion between missing fields and fields whose value is None, None-valued fields are always treated as missing while merging.

This method can be configured in numerous ways, including:

  • Whether new fields can be added to the document schema
  • Whether list fields should be treated as ordinary fields and merged as a whole rather than merging their elements
  • Whether to merge only specific fields, or all but certain fields
  • Mapping input document fields to different field names of this document
Parameters
documenta Document or DocumentView of the same type
fields:Nonean optional field or iterable of fields to which to restrict the merge. This can also be a dict mapping field names of the input document to field names of this document
omit_fields:Nonean optional field or iterable of fields to exclude from the merge
merge_lists:Truewhether to merge the elements of top-level list fields (e.g., tags) and label list fields (e.g., fiftyone.core.labels.Detections fields) rather than merging the entire top-level field like other field types. For label lists fields, existing fiftyone.core.label.Label elements are either replaced (when overwrite is True) or kept (when overwrite is False) when their id matches a label from the provided document
overwrite:Truewhether to overwrite (True) or skip (False) existing fields and label elements
expand_schema:Truewhether to dynamically add new fields encountered to the document schema. If False, an error is raised if any fields are not in the document schema
validate:Truewhether to validate values for existing fields
dynamic:Falsewhether to declare dynamic embedded document fields
Raises
AttributeErrorif expand_schema == False and a field does not exist
def set_field(self, field_name, value, create=True, validate=True, dynamic=False): (source)

Sets the value of a field of the document.

Parameters
field_namethe field name
valuethe field value
create:Truewhether to create the field if it does not exist
validate:Truewhether to validate values for existing fields
dynamic:Falsewhether to declare dynamic embedded document fields
Raises
ValueErrorif field_name is not an allowed field name
AttributeErrorif the field does not exist and create == False
def to_dict(self, include_private=False): (source)

Serializes the document to a JSON dictionary.

Parameters
include_private:Falsewhether to include private fields
Returns
a JSON dict
def to_json(self, pretty_print=False): (source)

Serializes the document to a JSON string.

The document ID and private fields are excluded in this representation.

Parameters
pretty_print:Falsewhether to render the JSON in human readable format with newlines and indentations
Returns
a JSON string
def to_mongo_dict(self, include_id=False): (source)

Serializes the document to a BSON dictionary equivalent to the representation that would be stored in the database.

Parameters
include_id:Falsewhether to include the document ID
Returns
a BSON dict
def update_fields(self, fields_dict, expand_schema=True, validate=True, dynamic=False): (source)

Sets the dictionary of fields on the document.

Parameters
fields_dicta dict mapping field names to values
expand_schema:Truewhether to dynamically add new fields encountered to the document schema. If False, an error is raised if any fields are not in the document schema
validate:Truewhether to validate values for existing fields
dynamic:Falsewhether to declare dynamic embedded document fields
Raises
AttributeErrorif expand_schema == False and a field does not exist

The dataset to which this document belongs, or None if it has not been added to a dataset.

@property
field_names = (source)

An ordered tuple of the public field names of this document.

Whether the document has been added to a dataset.

def _get_field_names(self, include_private=False, use_db_fields=False): (source)

Returns an ordered tuple of field names of this document.

Parameters
include_private:Falsewhether to include private fields
use_db_fields:Falsewhether to return database fields
Returns
a tuple of field names
def _iter_label_fields(self): (source)

Undocumented

def _parse_fields(self, fields=None, omit_fields=None): (source)

Undocumented

_dataset = (source)

Undocumented

Undocumented

@property
_collection = (source)

The fiftyone.core.collections.SampleCollection from which this document was taken, or None if it is not in a dataset.

The ObjectId of the document, or None if it has not been added to the database.

Whether the document has been inserted into the database.