Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 11 additions & 44 deletions pandas/tests/indexing/test_floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,43 +95,14 @@ def test_scalar_non_numeric(self, index_func, klass):
s = gen_obj(klass, i)

# getting
for idxr, getitem in [(lambda x: x.iloc, False), (lambda x: x, True)]:
with pytest.raises(KeyError, match="^3.0$"):
s[3.0]

if getitem:
error = KeyError
msg = r"^3\.0?$"
else:
error = TypeError
msg = (
r"cannot do (label|positional) indexing "
fr"on {type(i).__name__} with these indexers \[3\.0\] of "
r"type float|"
"Cannot index by location index with a "
"non-integer key"
)
with pytest.raises(error, match=msg):
idxr(s)[3.0]

# label based can be a TypeError or KeyError
if s.index.inferred_type in {
"categorical",
"string",
"unicode",
"mixed",
"period",
"timedelta64",
"datetime64",
}:
error = KeyError
msg = r"^3\.0$"
else:
error = TypeError
msg = (
r"cannot do (label|positional) indexing "
fr"on {type(i).__name__} with these indexers \[3\.0\] of "
"type float"
)
with pytest.raises(error, match=msg):
msg = "Cannot index by location index with a non-integer key"
with pytest.raises(TypeError, match=msg):
s.iloc[3.0]

with pytest.raises(KeyError, match="^3.0$"):
s.loc[3.0]

# contains
Expand Down Expand Up @@ -190,16 +161,12 @@ def test_scalar_with_mixed(self):
s2 = Series([1, 2, 3], index=["a", "b", "c"])
s3 = Series([1, 2, 3], index=["a", "b", 1.5])

# lookup in a pure stringstr
# with an invalid indexer
msg = (
r"cannot do label indexing "
r"on Index with these indexers \[1\.0\] of "
r"type float|"
"Cannot index by location index with a non-integer key"
)
# lookup in a pure string index with an invalid indexer

with pytest.raises(KeyError, match="^1.0$"):
s2[1.0]

msg = "Cannot index by location index with a non-integer key"
with pytest.raises(TypeError, match=msg):
s2.iloc[1.0]

Expand Down