Skip to content

Commit 69ffff3

Browse files
authored
perf: Use semi-join instead of unique for checking 1:N relationships (#362)
1 parent 071d6b9 commit 69ffff3

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

dataframely/functional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def require_relationship_one_to_at_least_one(
8484
columns, filtered to ensure a 1:{1,N} relationship.
8585
"""
8686
if drop_duplicates:
87-
return lhs.unique(on, keep="none").join(rhs.unique(on), on=on)
87+
return lhs.unique(on, keep="none").join(rhs, on=on, how="semi")
8888

89-
return lhs.join(rhs.unique(on), on=on)
89+
return lhs.join(rhs, on=on, how="semi")
9090

9191

9292
# ------------------------------------------------------------------------------------ #

tests/benches/test_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ def partitioned_dataset(dataset: pl.DataFrame) -> dict[str, pl.DataFrame]:
1515
"elevation",
1616
"aspect",
1717
"slope",
18-
idx=pl.int_range(pl.len(), dtype=pl.UInt32),
18+
idx=pl.int_range(pl.len(), dtype=pl.UInt32).shuffle(),
1919
),
2020
"second": dataset.select(
2121
"horizontal_distance_to_hydrology",
2222
"vertical_distance_to_hydrology",
2323
"horizontal_distance_to_roadways",
24-
idx=pl.int_range(pl.len(), dtype=pl.UInt32),
24+
idx=pl.int_range(pl.len(), dtype=pl.UInt32).shuffle(),
2525
),
2626
}
2727

0 commit comments

Comments
 (0)