Skip to content

Commit

Permalink
Fix min/max rows logic for Deduplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Jan 3, 2024
1 parent 7fe8783 commit 55fce47
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion python/lsst/daf/relation/_operations/_deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ def __str__(self) -> str:

def applied_min_rows(self, target: Relation) -> int:
# Docstring inherited.
return 1
return 1 if target.min_rows >= 1 else 0

def applied_max_rows(self, target: Relation) -> int | None:
# Docstring inherited.
if not target.columns:
return 1 if target.max_rows is None or target.max_rows >= 1 else 0
return target.max_rows

def commute(self, current: UnaryOperationRelation) -> UnaryCommutator:
# Docstring inherited.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ def test_attributes(self) -> None:
self.assertFalse(operation.is_order_dependent)
self.assertFalse(operation.is_count_dependent)

def test_min_max_rows(self) -> None:
"""Test min and max rows for edge-case deduplications."""
self.assertEqual(self.leaf.with_only_columns(set()).without_duplicates().min_rows, 1)
self.assertEqual(self.leaf.with_only_columns(set()).without_duplicates().max_rows, 1)
leaf0 = self.engine.make_leaf({self.a}, payload=iteration.RowSequence([]), name="leaf")
self.assertEqual(leaf0.without_duplicates().min_rows, 0)
self.assertEqual(leaf0.without_duplicates().max_rows, 0)
self.assertEqual(leaf0.with_only_columns([]).without_duplicates().min_rows, 0)
self.assertEqual(leaf0.with_only_columns([]).without_duplicates().max_rows, 0)

def test_backtracking_apply(self) -> None:
"""Test apply logic that involves reordering operations in the existing
tree to perform the new operation in a preferred engine.
Expand Down

0 comments on commit 55fce47

Please sign in to comment.