fix: raise HeadersNeeded instead of TypeError when subscripting a headerless Dataset by column name#648
Open
gaoflow wants to merge 1 commit into
Open
Conversation
…n headerless Dataset `Dataset.__getitem__` and `Dataset.__delitem__` both call `key in self.headers` when given a string key. When `headers` is `None` (no headers set), Python raises `TypeError: argument of type 'NoneType' is not iterable` instead of the library's own `HeadersNeeded` exception, which all other header-dependent operations already raise. Add a `self.headers is None` guard that raises `HeadersNeeded()` before the membership test in both dunder methods.
claudep
approved these changes
Jun 24, 2026
claudep
left a comment
Contributor
There was a problem hiding this comment.
Looks good, many thanks for your contribution!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #648 +/- ##
==========================================
+ Coverage 93.19% 93.22% +0.02%
==========================================
Files 29 29
Lines 3247 3261 +14
==========================================
+ Hits 3026 3040 +14
Misses 221 221 ☔ 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.__getitem__andDataset.__delitem__both evaluatekey in self.headerswhen given a string key. When no headers have been set (self.headers is None), Python raises an opaque:instead of the library's own
HeadersNeededexception, which every other header-dependent operation (e.g.sort,filter,stack_cols) already raises.Minimal reproduction:
Fix
Add a
self.headers is Noneguard at the top of theisinstance(key, str)branch in both dunder methods that raisesHeadersNeeded()before the membership test is attempted.Tests
Two new tests added to
DatasetTests:test_getitem_str_key_no_headers_raises— verifiesd["col"]raisesHeadersNeededtest_delitem_str_key_no_headers_raises— verifiesdel d["col"]raisesHeadersNeededAll 155 tests pass (
test_cli_export_githubdeselected as it is a pre-existing failure unrelated to this change).