class documentation

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_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
missing_valuea value to insert for missing or None-valued fields
unwindwhether 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_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.
Instance Variable _allow_missing Undocumented
Instance Variable _big_field Undocumented
Instance Variable _big_result Undocumented
Instance Variable _field Undocumented
Instance Variable _manual_field Undocumented
Instance Variable _missing_value Undocumented
Instance Variable _num_list_fields Undocumented
Instance Variable _raw Undocumented
Instance Variable _unwind 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.

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
def __init__(self, field_or_expr, expr=None, missing_value=None, unwind=False, _allow_missing=False, _big_result=True, _raw=False, _field=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
the list of field values
def to_mongo(self, sample_collection, big_field='values', 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
big_fieldUndocumented
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
_allow_missing = (source)

Undocumented

_big_field = (source)

Undocumented

_big_result = (source)

Undocumented

Undocumented

_manual_field = (source)

Undocumented

_missing_value = (source)

Undocumented

_num_list_fields = (source)

Undocumented

Undocumented

Undocumented

@property
_has_big_result = (source)

Whether the aggregation's result is returned across multiple documents.

This property affects the data passed to to_mongo at runtime.

@property
_is_big_batchable = (source)

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.