Skip to content

Commit 652711f

Browse files
committed
support grouped collections
1 parent cf178ae commit 652711f

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

fiftyone/core/collections.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -7728,17 +7728,19 @@ def count(self, field_or_expr=None, expr=None, safe=False):
77287728
"""
77297729

77307730
# Optimization: use estimated document count when possible
7731-
if (
7732-
isinstance(self, fod.Dataset)
7733-
and expr is None
7731+
if self._is_full_collection() and (
7732+
expr is None
77347733
and (
77357734
field_or_expr is None
7736-
or (field_or_expr == "frames" and self._has_frame_fields())
7735+
or (
7736+
etau.is_str(field_or_expr)
7737+
and field_or_expr == "frames"
7738+
and self._has_frame_fields()
7739+
)
77377740
)
77387741
):
77397742
frames = field_or_expr == "frames"
7740-
# pylint: disable=no-member
7741-
return self._estimated_count(frames=frames)
7743+
return self._dataset._estimated_count(frames=frames)
77427744

77437745
make = lambda field_or_expr: foa.Count(
77447746
field_or_expr, expr=expr, safe=safe
@@ -10616,6 +10618,22 @@ def _has_frame_fields(self):
1061610618
def _handle_id_fields(self, field_name):
1061710619
return _handle_id_fields(self, field_name)
1061810620

10621+
def _is_full_collection(self):
10622+
if isinstance(self, fod.Dataset) and self.media_type != fom.GROUP:
10623+
return True
10624+
10625+
# pylint:disable=no-member
10626+
if (
10627+
isinstance(self, fov.DatasetView)
10628+
and self._dataset.media_type == fom.GROUP
10629+
and len(self._stages) == 1
10630+
and isinstance(self._stages[0], fos.SelectGroupSlices)
10631+
and self._pipeline() == []
10632+
):
10633+
return True
10634+
10635+
return False
10636+
1061910637
def _is_label_field(self, field_name, label_type_or_types):
1062010638
try:
1062110639
label_type = self._get_label_field_type(field_name)

0 commit comments

Comments
 (0)