-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Improved error msg #32855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Improved error msg #32855
Changes from all commits
15f32b7
3ef72e6
5ce133a
5a3a43d
e89c7d6
1d4ad9c
8ebadc7
957f77e
b326574
c032efa
b1ee783
451b6b6
f601fd3
2817147
b275f21
f924bf0
88fadf8
90ac52b
217a35a
f37ed23
de6d168
91961d6
b792fea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2005,7 +2005,16 @@ def __getitem__(self, key): | |
raise ValueError("Invalid call for scalar access (getting)!") | ||
|
||
key = self._convert_key(key) | ||
return self.obj._get_value(*key, takeable=self._takeable) | ||
try: | ||
return self.obj._get_value(*key, takeable=self._takeable) | ||
except KeyError as err: | ||
if isinstance(self.obj.index, ABCMultiIndex): | ||
raise KeyError( | ||
f"Detected KeyError {err}, indexing with {key} " | ||
"failing for MultiIndex" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doing this on master, the DataFrame case is giving a reasonable message, while the Series case is unhelpful. Maybe condition this on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It the Series case goes down a different code path where an exception is raised in
|
||
) | ||
else: | ||
a-y-khan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise | ||
|
||
def __setitem__(self, key, value): | ||
if isinstance(key, tuple): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,3 +329,17 @@ def test_set_levels_with_iterable(): | |
[expected_sizes, colors], names=["size", "color"] | ||
) | ||
tm.assert_index_equal(result, expected) | ||
|
||
|
||
def test_at_indexing_fails_multiindex(): | ||
# GH9259 | ||
a-y-khan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cols = [("a_col", chr(i + 65)) for i in range(2)] | ||
idx = [("a_row", chr(i + 65)) for i in range(2)] | ||
df = pd.DataFrame( | ||
np.linspace(1, 4, 4).reshape(2, 2), | ||
index=pd.MultiIndex.from_tuples(idx), | ||
columns=pd.MultiIndex.from_tuples(cols), | ||
) | ||
|
||
with pytest.raises(KeyError, match=r".+? indexing with .+? failing for MultiIndex"): | ||
df.at["a_row", "A"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a similar problem for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiindex with
|
Uh oh!
There was an error while loading. Please reload this page.