class Values(Aggregation): (source)
Constructor: Values(field_or_expr, expr, missing_value, unwind, ...)
Extracts the values of the field from all samples in a collection.
Values aggregations are useful for efficiently extracting a slice of field or embedded field values across all samples in a collection. See the examples below for more details.
The dual function of Values
is
set_values()
,
which can be used to efficiently set a field or embedded field of all
samples in a collection by providing lists of values of same structure
returned by this aggregation.
Note
Unlike other aggregations, Values
does not automatically
unwind list fields, which ensures that the returned values match the
potentially-nested structure of the documents.
You can opt-in to unwinding specific list fields using the [] syntax, or you can pass the optional unwind=True parameter to unwind all supported list fields. See :ref:`aggregations-list-fields` for more information.
Examples:
import fiftyone as fo import fiftyone.zoo as foz from fiftyone import ViewField as F dataset = fo.Dataset() dataset.add_samples( [ fo.Sample( filepath="/path/to/image1.png", numeric_field=1.0, numeric_list_field=[1, 2, 3], ), fo.Sample( filepath="/path/to/image2.png", numeric_field=4.0, numeric_list_field=[1, 2], ), fo.Sample( filepath="/path/to/image3.png", numeric_field=None, numeric_list_field=None, ), ] ) # # Get all values of a field # aggregation = fo.Values("numeric_field") values = dataset.aggregate(aggregation) print(values) # [1.0, 4.0, None] # # Get all values of a list field # aggregation = fo.Values("numeric_list_field") values = dataset.aggregate(aggregation) print(values) # [[1, 2, 3], [1, 2], None] # # Get all values of transformed field # aggregation = fo.Values(2 * (F("numeric_field") + 1)) values = dataset.aggregate(aggregation) print(values) # [4.0, 10.0, None] # # Get values from a label list field # dataset = foz.load_zoo_dataset("quickstart") # list of `Detections` aggregation = fo.Values("ground_truth") detections = dataset.aggregate(aggregation) # list of lists of `Detection` instances aggregation = fo.Values("ground_truth.detections") detections = dataset.aggregate(aggregation) # list of lists of detection labels aggregation = fo.Values("ground_truth.detections.label") labels = dataset.aggregate(aggregation)
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 |
missing | a value to insert for missing or None-valued fields |
unwind | whether to automatically unwind all recognized list fields (True) or unwind all list fields except the top-level sample field (-1) |
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. |
Instance Variable | _allow |
Undocumented |
Instance Variable | _big |
Undocumented |
Instance Variable | _big |
Undocumented |
Instance Variable | _field |
Undocumented |
Instance Variable | _manual |
Undocumented |
Instance Variable | _missing |
Undocumented |
Instance Variable | _num |
Undocumented |
Instance Variable | _raw |
Undocumented |
Instance Variable | _unwind |
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. |
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 |
Undocumented
Returns the MongoDB aggregation pipeline for this aggregation.
Parameters | |
sample | the
fiftyone.core.collections.SampleCollection to which
the aggregation is being applied |
big | Undocumented |
context:None | a path context from which to resolve |
Returns | |
a MongoDB aggregation pipeline (list of dicts) |
Returns a list of [name, value] lists describing the parameters of this aggregation instance.
Returns | |
a list of [name, value] lists |
Whether the aggregation's result is returned across multiple documents.
This property affects the data passed to to_mongo
at runtime.
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.
Aggregation
classes for which _is_big_batchable
may be
True must accept an optional big_field parameter in their
to_mongo
method that specifies the field name to use in its
$project stage.