From 7137163e1bb88ab62a5192d4772f2d61c461e0ec Mon Sep 17 00:00:00 2001 From: Oliver Borchert Date: Mon, 6 Jul 2026 18:51:16 +0200 Subject: [PATCH 1/2] perf: Use semi-join instead of `unique` for checking 1:N relationships --- dataframely/functional.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dataframely/functional.py b/dataframely/functional.py index b099fe54..baabc713 100644 --- a/dataframely/functional.py +++ b/dataframely/functional.py @@ -84,9 +84,9 @@ def require_relationship_one_to_at_least_one( columns, filtered to ensure a 1:{1,N} relationship. """ if drop_duplicates: - return lhs.unique(on, keep="none").join(rhs.unique(on), on=on) + return lhs.unique(on, keep="none").join(rhs, on=on, how="semi") - return lhs.join(rhs.unique(on), on=on) + return lhs.join(rhs, on=on, how="semi") # ------------------------------------------------------------------------------------ # From 3574fd7ef87e8da92a496f950e9bd1ddc68bb4ee Mon Sep 17 00:00:00 2001 From: Oliver Borchert Date: Mon, 6 Jul 2026 22:41:25 +0200 Subject: [PATCH 2/2] Fix benchmark --- tests/benches/test_collection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/benches/test_collection.py b/tests/benches/test_collection.py index f3a1aa3b..0bf0cb5f 100644 --- a/tests/benches/test_collection.py +++ b/tests/benches/test_collection.py @@ -15,13 +15,13 @@ def partitioned_dataset(dataset: pl.DataFrame) -> dict[str, pl.DataFrame]: "elevation", "aspect", "slope", - idx=pl.int_range(pl.len(), dtype=pl.UInt32), + idx=pl.int_range(pl.len(), dtype=pl.UInt32).shuffle(), ), "second": dataset.select( "horizontal_distance_to_hydrology", "vertical_distance_to_hydrology", "horizontal_distance_to_roadways", - idx=pl.int_range(pl.len(), dtype=pl.UInt32), + idx=pl.int_range(pl.len(), dtype=pl.UInt32).shuffle(), ), }