Fix TypeError when stacking two headerless Datasets with stack_cols#651
Open
vineethsaivs wants to merge 1 commit into
Open
Fix TypeError when stacking two headerless Datasets with stack_cols#651vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
Dataset.stack_cols() explicitly permits two headerless datasets: the header guard only raises HeadersNeeded when exactly one side has headers, and the header concatenation catches None + None to set new_headers=None. But it then did 'for column in self.headers', which iterates None and raised 'TypeError: NoneType object is not iterable', so column-level stacking crashed on inputs that row-level stack() handles fine. When neither dataset has headers, iterate columns by index with get_col() instead of by header name. The headered path is unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #651 +/- ##
==========================================
+ Coverage 93.19% 93.28% +0.09%
==========================================
Files 29 29
Lines 3247 3263 +16
==========================================
+ Hits 3026 3044 +18
+ Misses 221 219 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
Dataset.stack_cols()crashes with an opaqueTypeErrorwhen both datasets have no headers, even though the method is written to allow that case:The method already anticipates two headerless datasets:
HeadersNeededonly when exactly one side has headers, andNone + Noneand setsnew_headers = None.But it then does
for column in self.headers:to copy the columns, which iteratesNoneand raises. Row-levelstack()handles headerless datasets fine, so the column-level crash is an internal inconsistency rather than intended behavior.Fix
When neither dataset has headers, copy the columns by index with
get_col()instead of by header name. The existing headered path is unchanged (it is just moved underif self.headers:), so headered stacking behaves exactly as before.Test
Added
test_column_stacking_headerless, which stacks two headerless datasets and asserts the combined rows andheaders is None. It fails on the current code with theTypeErrorabove and passes with this change; the existingtest_column_stacking(headered) still passes.Note
This touches the same method as the open PR #649 ("Raise TypeError for invalid Dataset instance"), but a different line: #649 changes the
isinstance(other, Dataset)guard, while this fixes the headerless column-iteration path. The two do not overlap and either order rebases trivially.