«
class documentation

Extracts the value type(s) in a specified list field across all samples in a collection.

Examples:

from datetime import datetime
import fiftyone as fo

dataset = fo.Dataset()

sample1 = fo.Sample(
    filepath="image1.png",
    ground_truth=fo.Classification(
        label="cat",
        info=[
            fo.DynamicEmbeddedDocument(
                task="initial_annotation",
                author="Alice",
                timestamp=datetime(1970, 1, 1),
                notes=["foo", "bar"],
            ),
            fo.DynamicEmbeddedDocument(
                task="editing_pass",
                author="Bob",
                timestamp=datetime.utcnow(),
            ),
        ],
    ),
)

sample2 = fo.Sample(
    filepath="image2.png",
    ground_truth=fo.Classification(
        label="dog",
        info=[
            fo.DynamicEmbeddedDocument(
                task="initial_annotation",
                author="Bob",
                timestamp=datetime(2018, 10, 18),
                notes=["spam", "eggs"],
            ),
        ],
    ),
)

dataset.add_samples([sample1, sample2])

# Determine that `ground_truth.info` contains embedded documents
aggregation = fo.ListSchema("ground_truth.info")
print(dataset.aggregate(aggregation))
# fo.EmbeddedDocumentField

# Determine the fields of the embedded documents in the list
aggregation = fo.Schema("ground_truth.info[]")
print(dataset.aggregate(aggregation))
# {'task': StringField, ..., 'notes': ListField}

# Determine the type of the values in the nested `notes` list field
# Since `ground_truth.info` is not yet declared on the dataset's
# schema, we must manually include `[]` to unwind the info lists
aggregation = fo.ListSchema("ground_truth.info[].notes")
print(dataset.aggregate(aggregation))
# fo.StringField

# Declare the `ground_truth.info` field
dataset.add_sample_field(
    "ground_truth.info",
    fo.ListField,
    subfield=fo.EmbeddedDocumentField,
    embedded_doc_type=fo.DynamicEmbeddedDocument,
)

# Now we can inspect the nested `notes` field without unwinding
aggregation = fo.ListSchema("ground_truth.info.notes")
print(dataset.aggregate(aggregation))
# fo.StringField
Parameters
field_or_expra field name, embedded.field.name, fiftyone.core.expressions.ViewExpression, or MongoDB expression defining the field or expression to aggregate
expra fiftyone.core.expressions.ViewExpression or MongoDB expression to apply to field_or_expr (which must be a field) before aggregating
Method __init__ Undocumented
Method default_result Returns the default result for this aggregation.
Method parse_result Parses the output of to_mongo.
Method to_mongo Returns the MongoDB aggregation pipeline for this aggregation.
Method _kwargs Returns a list of [name, value] lists describing the parameters of this aggregation instance.

Inherited from Aggregation:

Method __eq__ Undocumented
Method __repr__ Undocumented
Method __str__ Undocumented
Property field_name The name of the field being computed on, if any.
Property safe Whether nan/inf values will be ignored when dealing with floating point values.
Class Method _from_dict Creates an Aggregation instance from a serialized JSON dict representation of it.
Method _needs_frames Whether the aggregation requires frame labels of video samples to be attached.
Method _needs_group_slices Whether the aggregation requires group slice(s) to be attached.
Method _serialize Returns a JSON dict representation of the Aggregation.
Instance Variable _expr Undocumented
Instance Variable _field_name Undocumented
Instance Variable _safe Undocumented
Instance Variable _uuid Undocumented
Property _has_big_result Whether the aggregation's result is returned across multiple documents.
Property _is_big_batchable Whether the aggregation has big results and its pipeline is defined by a single $project stage and thus can be combined with other such aggregations.
def __init__(self, field_or_expr, expr=None): (source)
def default_result(self): (source)

Returns the default result for this aggregation.

Returns
[]
def parse_result(self, d): (source)

Parses the output of to_mongo.

Parameters
dthe result dict
Returns
a fiftyone.core.fields.Field or list of fiftyone.core.fields.Field instances describing the value type(s) in the list
def to_mongo(self, sample_collection, context=None): (source)

Returns the MongoDB aggregation pipeline for this aggregation.

Parameters
sample_collectionthe fiftyone.core.collections.SampleCollection to which the aggregation is being applied
context:Nonea path context from which to resolve
Returns
a MongoDB aggregation pipeline (list of dicts)
def _kwargs(self): (source)

Returns a list of [name, value] lists describing the parameters of this aggregation instance.

Returns
a list of [name, value] lists