class documentation
class ListSchema(Aggregation): (source)
Constructor: ListSchema(field_or_expr, expr)
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 | a field name, embedded.field.name,
fiftyone.core.expressions.ViewExpression , or
MongoDB expression
defining the field or expression to aggregate |
expr | a 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 |
Returns the default result for this aggregation. |
Method | parse |
Parses the output of to_mongo . |
Method | to |
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 |
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 |
Creates an Aggregation instance from a serialized JSON dict representation of it. |
Method | _needs |
Whether the aggregation requires frame labels of video samples to be attached. |
Method | _needs |
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 |
Undocumented |
Instance Variable | _safe |
Undocumented |
Instance Variable | _uuid |
Undocumented |
Property | _has |
Whether the aggregation's result is returned across multiple documents. |
Property | _is |
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. |
Parses the output of to_mongo
.
Parameters | |
d | the result dict |
Returns | |
a fiftyone.core.fields.Field or list of
fiftyone.core.fields.Field instances describing the value
type(s) in the list |
Returns the MongoDB aggregation pipeline for this aggregation.
Parameters | |
sample | the
fiftyone.core.collections.SampleCollection to which
the aggregation is being applied |
context:None | a path context from which to resolve |
Returns | |
a MongoDB aggregation pipeline (list of dicts) |