Skip to content

Commit

Permalink
CLN: Remove remaining non-context pytest.raises
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung committed Mar 25, 2019
1 parent cbffba1 commit 9fbbedf
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 182 deletions.
10 changes: 7 additions & 3 deletions pandas/tests/arrays/sparse/test_libsparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
elen = [3, 2, 3, 2]
_check_case(xloc, xlen, yloc, ylen, eloc, elen)

def test_intindex_make_union(self):
def test_int_index_make_union(self):
a = IntIndex(5, np.array([0, 3, 4], dtype=np.int32))
b = IntIndex(5, np.array([0, 2], dtype=np.int32))
res = a.make_union(b)
Expand All @@ -184,7 +184,9 @@ def test_intindex_make_union(self):

a = IntIndex(5, np.array([0, 1], dtype=np.int32))
b = IntIndex(4, np.array([0, 1], dtype=np.int32))
with pytest.raises(ValueError):

msg = "Indices must reference same underlying length"
with pytest.raises(ValueError, match=msg):
a.make_union(b)


Expand All @@ -197,7 +199,9 @@ def _check_correct(a, b, expected):
assert (result.equals(expected))

def _check_length_exc(a, longer):
pytest.raises(Exception, a.intersect, longer)
msg = "Indices must reference same underlying length"
with pytest.raises(Exception, match=msg):
a.intersect(longer)

def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
xindex = BlockIndex(TEST_LENGTH, xloc, xlen)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def check_pow(self, lhs, arith1, rhs):

if (is_scalar(lhs) and is_scalar(rhs) and
_is_py3_complex_incompat(result, expected)):
pytest.raises(AssertionError, tm.assert_numpy_array_equal,
result, expected)
with pytest.raises(AssertionError):
tm.assert_numpy_array_equal(result, expected)
else:
tm.assert_almost_equal(result, expected)

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/frame/test_nonunique_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,8 @@ def test_columns_with_dups(self):
[[1, 2, 1., 2., 3., 'foo', 'bar']], columns=list('ABCDEFG'))
assert_frame_equal(df, expected)

# this is an error because we cannot disambiguate the dup columns
pytest.raises(Exception, lambda x: DataFrame(
[[1, 2, 'foo', 'bar']], columns=['a', 'a', 'a', 'a']))
# TODO: Is this an error because we cannot disambiguate the dupes?
DataFrame([[1, 2, 'foo', 'bar']], columns=['a', 'a', 'a', 'a'])

# dups across blocks
df_float = DataFrame(np.random.randn(10, 3), dtype='float64')
Expand Down
21 changes: 14 additions & 7 deletions pandas/tests/indexes/interval/test_interval_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def test_get_loc_scalar(self, closed, scalar):
if scalar in correct[closed].keys():
assert idx.get_loc(scalar) == correct[closed][scalar]
else:
pytest.raises(KeyError, idx.get_loc, scalar)
with pytest.raises(KeyError, match=str(scalar)):
idx.get_loc(scalar)

def test_slice_locs_with_interval(self):

Expand Down Expand Up @@ -89,13 +90,19 @@ def test_slice_locs_with_interval(self):
# unsorted duplicates
index = IntervalIndex.from_tuples([(0, 2), (2, 4), (0, 2)])

pytest.raises(KeyError, index.slice_locs(
start=Interval(0, 2), end=Interval(2, 4)))
pytest.raises(KeyError, index.slice_locs(start=Interval(0, 2)))
with pytest.raises(KeyError):
index.slice_locs(start=Interval(0, 2), end=Interval(2, 4))

with pytest.raises(KeyError):
index.slice_locs(start=Interval(0, 2))

assert index.slice_locs(end=Interval(2, 4)) == (0, 2)
pytest.raises(KeyError, index.slice_locs(end=Interval(0, 2)))
pytest.raises(KeyError, index.slice_locs(
start=Interval(2, 4), end=Interval(0, 2)))

with pytest.raises(KeyError):
index.slice_locs(end=Interval(0, 2))

with pytest.raises(KeyError):
index.slice_locs(start=Interval(2, 4), end=Interval(0, 2))

# another unsorted duplicates
index = IntervalIndex.from_tuples([(0, 2), (0, 2), (2, 4), (1, 3)])
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/indexing/multiindex/test_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ def test_partial_ix_missing(
# assert (self.ymd.loc[2000]['A'] == 0).all()

# Pretty sure the second (and maybe even the first) is already wrong.
pytest.raises(Exception, ymd.loc.__getitem__, (2000, 6))
pytest.raises(Exception, ymd.loc.__getitem__, (2000, 6), 0)
with pytest.raises(Exception):
ymd.loc[(2000, 6)]
with pytest.raises(Exception):
ymd.loc[(2000, 6), 0]

# ---------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexing/test_floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def test_scalar_non_numeric(self):
# for idxr in [lambda x: x.ix,
# lambda x: x]:
# s2 = s.copy()
# def f():
#
# with pytest.raises(TypeError):
# idxr(s2)[3.0] = 0
# pytest.raises(TypeError, f)
pass

else:
Expand Down
Loading

0 comments on commit 9fbbedf

Please sign in to comment.