Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary fields should support frame-level input paths #4841

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

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
Loading