-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API/BUG: make .at raise same exceptions as .loc #31724
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
Changes from 1 commit
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 |
---|---|---|
|
@@ -136,30 +136,48 @@ def test_at_to_fail(self): | |
result = s.at["a"] | ||
assert result == 1 | ||
msg = ( | ||
"At based indexing on an non-integer index can only have " | ||
"non-integer indexers" | ||
"cannot do label indexing on <class 'pandas.core.indexes.base.Index'> " | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
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. I have to say that I found the previous error message more readable .. 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. I generally agree, that suggests we should improve the existing messages for "loc" |
||
r"with these indexers \[0\] of <class 'int'>" | ||
) | ||
with pytest.raises(ValueError, match=msg): | ||
with pytest.raises(TypeError, match=msg): | ||
s.at[0] | ||
with pytest.raises(TypeError, match=msg): | ||
# .at should match .loc | ||
s.loc[0] | ||
|
||
df = DataFrame({"A": [1, 2, 3]}, index=list("abc")) | ||
result = df.at["a", "A"] | ||
assert result == 1 | ||
with pytest.raises(ValueError, match=msg): | ||
with pytest.raises(TypeError, match=msg): | ||
df.at["a", 0] | ||
with pytest.raises(TypeError, match=msg): | ||
# .at should match .loc | ||
df.loc["a", 0] | ||
|
||
s = Series([1, 2, 3], index=[3, 2, 1]) | ||
result = s.at[1] | ||
assert result == 3 | ||
msg = "At based indexing on an integer index can only have integer indexers" | ||
with pytest.raises(ValueError, match=msg): | ||
|
||
with pytest.raises(KeyError, match="a"): | ||
s.at["a"] | ||
with pytest.raises(KeyError, match="a"): | ||
# .at should match .loc | ||
s.loc["a"] | ||
|
||
df = DataFrame({0: [1, 2, 3]}, index=[3, 2, 1]) | ||
result = df.at[1, 0] | ||
assert result == 3 | ||
with pytest.raises(ValueError, match=msg): | ||
with pytest.raises(KeyError, match="a"): | ||
df.at["a", 0] | ||
with pytest.raises(KeyError, match="a"): | ||
# .at should match .loc | ||
df.loc["a", 0] | ||
|
||
with pytest.raises(KeyError, match="a"): | ||
df.at[1, "a"] | ||
with pytest.raises(KeyError, match="a"): | ||
# .at should match .loc | ||
df.loc[1, "a"] | ||
|
||
# GH 13822, incorrect error string with non-unique columns when missing | ||
# column is accessed | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should mention the
KeyError
here as well?