Skip to content

CLN/TST: parametrize some tests in tests.indexing.test_float #32187

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

Merged
merged 15 commits into from
Feb 26, 2020
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
af764dd
TST: cleanups
jbrockmendel Feb 18, 2020
99e781c
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 19, 2020
0eb6bad
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 21, 2020
59684e0
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 22, 2020
a6b7b84
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 22, 2020
b0be2d9
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 22, 2020
576e2a1
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 23, 2020
46c37f0
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 24, 2020
01e0386
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 24, 2020
f9d7902
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 25, 2020
b2efc75
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 25, 2020
8e71240
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 26, 2020
1fb8d02
troubleshoot
jbrockmendel Feb 26, 2020
b8517fa
Merge branch 'master' of https://github.com/pandas-dev/pandas into tst-7
jbrockmendel Feb 26, 2020
7f82cfa
troubleshoot travis
jbrockmendel Feb 26, 2020
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
87 changes: 33 additions & 54 deletions pandas/tests/indexing/test_floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,9 @@ def test_scalar_non_numeric(self, index_func, klass):
s2.loc[3.0] = 10
assert s2.index.is_object()

for idxr in [lambda x: x]:
s2 = s.copy()
idxr(s2)[3.0] = 0
assert s2.index.is_object()
s2 = s.copy()
s2[3.0] = 0
assert s2.index.is_object()

@pytest.mark.parametrize(
"index_func",
Expand Down Expand Up @@ -250,12 +249,7 @@ def test_scalar_integer(self, index_func, klass):

# integer index
i = index_func(5)

if klass is Series:
# TODO: Should we be passing index=i here?
obj = Series(np.arange(len(i)))
else:
obj = DataFrame(np.random.randn(len(i), len(i)), index=i, columns=i)
obj = gen_obj(klass, i)

# coerce to equal int
for idxr, getitem in [(lambda x: x.loc, False), (lambda x: x, True)]:
Expand Down Expand Up @@ -313,7 +307,7 @@ def test_scalar_float(self, klass):
result = idxr(s2)[indexer]
self.check(result, s, 3, getitem)

# random integer is a KeyError
# random float is a KeyError
with pytest.raises(KeyError, match=r"^3\.5$"):
idxr(s)[3.5]

Expand Down Expand Up @@ -429,15 +423,6 @@ def test_slice_integer(self):
indexer = slice(3, 5)
self.check(result, s, indexer, False)

# positional indexing
msg = (
"cannot do slice indexing "
fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of "
"type float"
)
with pytest.raises(TypeError, match=msg):
s[l]

# getitem out-of-bounds
for l in [slice(-6, 6), slice(-6.0, 6.0)]:

Expand Down Expand Up @@ -485,23 +470,6 @@ def test_slice_integer(self):
with pytest.raises(TypeError, match=msg):
s[l]

# setitem
for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]:

sc = s.copy()
sc.loc[l] = 0
result = sc.loc[l].values.ravel()
assert (result == 0).all()

# positional indexing
msg = (
"cannot do slice indexing "
fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of "
"type float"
)
with pytest.raises(TypeError, match=msg):
s[l] = 0

@pytest.mark.parametrize("l", [slice(2, 4.0), slice(2.0, 4), slice(2.0, 4.0)])
def test_integer_positional_indexing(self, l):
""" make sure that we are raising on positional indexing
Expand Down Expand Up @@ -584,22 +552,34 @@ def test_slice_integer_frame_getitem(self, index_func):
with pytest.raises(TypeError, match=msg):
s[l]

@pytest.mark.parametrize("l", [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)])
@pytest.mark.parametrize(
"index_func", [tm.makeIntIndex, tm.makeRangeIndex],
)
def test_float_slice_getitem_with_integer_index_raises(self, l, index_func):

# similar to above, but on the getitem dim (of a DataFrame)
index = index_func(5)

s = DataFrame(np.random.randn(5, 2), index=index)

# setitem
for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]:
sc = s.copy()
sc.loc[l] = 0
result = sc.loc[l].values.ravel()
assert (result == 0).all()

sc = s.copy()
sc.loc[l] = 0
result = sc.loc[l].values.ravel()
assert (result == 0).all()
# positional indexing
msg = (
"cannot do slice indexing "
fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of "
"type float"
)
with pytest.raises(TypeError, match=msg):
s[l] = 0

# positional indexing
msg = (
"cannot do slice indexing "
fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of "
"type float"
)
with pytest.raises(TypeError, match=msg):
s[l] = 0
with pytest.raises(TypeError, match=msg):
s[l]

@pytest.mark.parametrize("l", [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)])
@pytest.mark.parametrize("klass", [Series, DataFrame])
Expand All @@ -614,10 +594,9 @@ def test_slice_float(self, l, klass):

# getitem
result = idxr(s)[l]
if isinstance(s, Series):
tm.assert_series_equal(result, expected)
else:
tm.assert_frame_equal(result, expected)
assert isinstance(result, type(s))
tm.assert_equal(result, expected)

# setitem
s2 = s.copy()
idxr(s2)[l] = 0
Expand Down