Skip to content

Fix get_random_subset crash with composite keys - #2982

Open
cpruijsen wants to merge 1 commit into
sdv-dev:mainfrom
cpruijsen:fix/issue-2943
Open

cpruijsen wants to merge 1 commit into
sdv-dev:mainfrom
cpruijsen:fix/issue-2943

Conversation

@cpruijsen

Copy link
Copy Markdown

Treat composite keys as a Series of tuples in get_random_subset (itertuples(index=False, name=None)), matching print_referential_integrity, and use that Series for both .unique() and parent-row .isin.

Resolves #2943.

get_random_subset crashed with AttributeError: 'DataFrame' object has no attribute 'unique' when a relationship used a composite foreign key. That is the reporter's credit_card_transactions demo: sd254_cards is keyed by ['User', 'CARD INDEX'], and the child foreign keys are ['User', 'Card']. Indexing the child table with that list returns a DataFrame, which has no .unique().

The same Series-only assumption broke parent-row filtering: DataFrame.isin on a set of tuples does not drop composite keys, so sampling a child of a composite-key parent could keep or drop the wrong parent rows.

A single-column key is still a scalar Series, so existing tests stay valid.

Alternative: only special-case .unique() on a DataFrame, or filter parents with the existing _get_unreferenced_keys merge (already used by _get_rows_to_drop). The unique-only guard would leave the silent isin bug. Can switch to the merge helper.

@cpruijsen
cpruijsen requested a review from a team as a code owner September 11, 2026 11:19
@cpruijsen
cpruijsen requested review from amontanez24 and removed request for a team September 11, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_random_subset fails with composite key

1 participant