Skip to content

Commit

Permalink
Merge pull request #4755 from voxel51/merge/release/v0.25.1
Browse files Browse the repository at this point in the history
Merge `release/v0.25.1` to `develop`
  • Loading branch information
benjaminpkane authored Aug 30, 2024
2 parents b7ba4f7 + 127a51f commit 3ab7f5b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 21 deletions.
2 changes: 1 addition & 1 deletion fiftyone/core/stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3416,7 +3416,7 @@ def _make_flat_pipeline(self, sample_collection):
)

if match_expr is not None:
pipeline.append({"$match": match_expr})
pipeline.append({"$match": {"$expr": match_expr}})

if sort_expr is not None:
order = -1 if self._reverse else 1
Expand Down
18 changes: 4 additions & 14 deletions fiftyone/operators/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,8 @@ def set(self, key, value=None):
value (None): the value, if key is a string
"""
d = key if isinstance(key, dict) else {key: value}

args = {}
for k, v in d.items():
super().set(k, v)
pydash.set_(args, k, v)

self._ctx.ops.patch_panel_state(args)
super().set(d)
self._ctx.ops.patch_panel_state(d)

def clear(self):
"""Clears the panel state."""
Expand Down Expand Up @@ -262,13 +257,8 @@ def set(self, key, value=None):
value (None): the value, if key is a string
"""
d = key if isinstance(key, dict) else {key: value}

args = {}
for k, v in d.items():
super().set(k, v)
pydash.set_(args, k, v)

self._ctx.ops.patch_panel_data(args)
super().set(d)
self._ctx.ops.patch_panel_data(d)

def get(self, key, default=None):
raise WriteOnlyError("Panel data is write-only")
Expand Down
9 changes: 9 additions & 0 deletions tests/unittests/group_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,15 @@ def test_flatten(self):
)
self.assertListEqual(view.values("frame_number"), [1, 1])

@drop_datasets
def test_match_expr(self):
dataset = _make_group_by_dataset()

view = dataset.group_by(
"frame_number", flat=True, match_expr=(F().length() > 1)
)
self.assertDictEqual(view.count_values("frame_number"), {1: 2, 2: 2})

@drop_datasets
def test_group_by_group_dataset(self):
dataset = _make_group_by_group_dataset()
Expand Down
66 changes: 60 additions & 6 deletions tests/unittests/panels/panel_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ def test_panel_ref_data_setattr(mock_ctx):
)


def test_panel_ref_data_getattr_raises_write_only_error(mock_ctx):
data = PanelRefData(mock_ctx)
with pytest.raises(WriteOnlyError):
_ = data.test_key


def test_panel_ref_data_clear(mock_ctx):
data = PanelRefData(mock_ctx)
data.test_key = "test_value"
Expand Down Expand Up @@ -189,6 +183,39 @@ def test_panel_ref_set_state(mock_ctx):
)


def test_panel_ref_set_state_dict(mock_ctx):
panel_ref = PanelRef(mock_ctx)
panel_ref.set_state({"test_key": "test_value"})
assert panel_ref._state._data["test_key"] == "test_value"
mock_ctx.ops.patch_panel_state.assert_called_with(
{"test_key": "test_value"}
)


def test_panel_ref_set_state_deep_path(mock_ctx):
panel_ref = PanelRef(mock_ctx)
panel_ref.set_state("nested.key.path", "test_value")
assert panel_ref._state._data["nested"]["key"]["path"] == "test_value"
mock_ctx.ops.patch_panel_state.assert_called_with(
{"nested.key.path": "test_value"}
)


def test_panel_ref_set_state_deep_path_dict(mock_ctx):
panel_ref = PanelRef(mock_ctx)
panel_ref.set_state({"nested.key.path": "test_value"})
assert panel_ref._state._data["nested"]["key"]["path"] == "test_value"
mock_ctx.ops.patch_panel_state.assert_called_with(
{"nested.key.path": "test_value"}
)


def test_panel_ref_get_data_raises_write_only_error(mock_ctx):
panel_ref = PanelRef(mock_ctx)
with pytest.raises(WriteOnlyError):
_ = panel_ref.data.get("test_key")


def test_panel_ref_get_state(mock_ctx):
panel_ref = PanelRef(mock_ctx)
panel_ref.set_state("test_key", "test_value")
Expand All @@ -202,3 +229,30 @@ def test_panel_ref_set_data(mock_ctx):
mock_ctx.ops.patch_panel_data.assert_called_with(
{"test_key": "test_value"}
)


def test_panel_ref_set_data_dict(mock_ctx):
panel_ref = PanelRef(mock_ctx)
panel_ref.set_data({"test_key": "test_value"})
assert panel_ref._data._data["test_key"] == "test_value"
mock_ctx.ops.patch_panel_data.assert_called_with(
{"test_key": "test_value"}
)


def test_panel_ref_set_data_deep_path(mock_ctx):
panel_ref = PanelRef(mock_ctx)
panel_ref.set_data("nested.key.path", "test_value")
assert panel_ref._data._data["nested"]["key"]["path"] == "test_value"
mock_ctx.ops.patch_panel_data.assert_called_with(
{"nested.key.path": "test_value"}
)


def test_panel_ref_set_data_deep_path_dict(mock_ctx):
panel_ref = PanelRef(mock_ctx)
panel_ref.set_data({"nested.key.path": "test_value"})
assert panel_ref._data._data["nested"]["key"]["path"] == "test_value"
mock_ctx.ops.patch_panel_data.assert_called_with(
{"nested.key.path": "test_value"}
)

0 comments on commit 3ab7f5b

Please sign in to comment.