Skip to content

Commit

Permalink
Merge pull request #4841 from voxel51/bug/create-summary-field-operator
Browse files Browse the repository at this point in the history
Summary fields should support frame-level input paths
  • Loading branch information
brimoor authored Sep 25, 2024
2 parents 17be412 + b00a4de commit 869bd0b
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions fiftyone/operators/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,31 @@ def execute(self, ctx):

def _create_summary_field_inputs(ctx, inputs):
schema = ctx.dataset.get_field_schema(flat=True)
if ctx.dataset._has_frame_fields():
frame_schema = ctx.dataset.get_frame_field_schema(flat=True)
schema.update(
{
ctx.dataset._FRAMES_PREFIX + path: field
for path, field in frame_schema.items()
}
)

categorical_field_types = (fo.StringField, fo.BooleanField)
numeric_field_types = (
fo.FloatField,
fo.IntField,
fo.DateField,
fo.DateTimeField,
)

schema = {
p: f
for p, f in schema.items()
if (
isinstance(f, categorical_field_types)
or isinstance(f, numeric_field_types)
)
}

path_keys = list(schema.keys())
path_selector = types.AutocompleteView()
Expand Down Expand Up @@ -1215,17 +1240,7 @@ def _create_summary_field_inputs(ctx, inputs):
)

field = schema.get(path, None)
if isinstance(field, (fo.StringField, fo.BooleanField)):
field_type = "categorical"
elif isinstance(
field,
(fo.FloatField, fo.IntField, fo.DateField, fo.DateTimeField),
):
field_type = "numeric"
else:
field_type = None

if field_type == "categorical":
if isinstance(field, categorical_field_types):
inputs.bool(
"include_counts",
label="Include counts",
Expand All @@ -1235,7 +1250,7 @@ def _create_summary_field_inputs(ctx, inputs):
),
default=False,
)
elif field_type == "numeric":
elif isinstance(field, numeric_field_types):
group_prefix = path.rsplit(".", 1)[0] + "."
group_by_keys = sorted(p for p in schema if p.startswith(group_prefix))
group_by_selector = types.AutocompleteView()
Expand Down

0 comments on commit 869bd0b

Please sign in to comment.