Reject a repeated column name in Dataset.remove_columns - #8529
Open
LeSingh1 wants to merge 2 commits into
Open
Conversation
…lumns Neither method deduplicated, and the two failure modes differed. select_columns handed the repeated name to pyarrow, which built a table with two identically named columns while Features kept one entry, so the result was a Dataset whose column_names was ['a', 'a'] but whose features had a single 'a'. No error at any point. remove_columns deleted the same feature twice and surfaced the second delete as a bare KeyError with no indication of what was wrong. Reject the repeat in both, in the style of the missing-column check that already sits above each.
PR huggingface#8368 already rejects a repeated name in select_columns, on both Dataset and IterableDataset. Dropping that half here leaves only Dataset.remove_columns, which huggingface#8368 does not touch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Dataset.remove_columnsdoes not deduplicate its argument, so a repeated name deletes the same feature twice:The second
del dataset._info.features[column_name]raises a bareKeyError, with nothing pointing at the repeat. A duplicate is easy to produce when the list is built programmatically, and the error does not say what was wrong.The fix
Reject the repeat, in the style of the missing-column check that already sits directly above it.
Scope
I originally had this covering
select_columnstoo, where a repeat produced aDatasetwhosecolumn_nameswas['a', 'a']while itsfeatureshad one entry. @AbdullahRasheed45's #8368 already fixes that, on bothDatasetandIterableDataset, so I have dropped that half — I only spotted #8368 after opening this. What is left isDataset.remove_columns, which #8368 does not touch, so the two do not overlap.I chose rejecting over silently deduplicating because quietly changing the result seemed worse than saying what is wrong, and it matches how #8368 handles the sibling method. Happy to make it a dedup instead if you would rather.
Verification
The new test fails on
mainand passes with the change, for bothin_memoryvalues. Comparing fulltests/test_arrow_dataset.pyruns with and without the change shows no test that fails only with it. One failure is present either way,test_dataset_to_iterable_dataset, which needs PyTorch and is not installed in my venv.