Skip to content

Commit 0aba225

Browse files
committed
Fix pytest catchwarnings bugs on Python2.7 ???
1 parent c51d21f commit 0aba225

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

pandas/tests/sparse/frame/test_frame.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ def test_iloc(self):
458458
iframe.iloc[:, 0].sp_index)
459459

460460
def test_set_value(self):
461-
462461
# ok, as the index gets converted to object
463462
frame = self.frame.copy()
464463
with tm.assert_produces_warning((FutureWarning,
@@ -593,8 +592,9 @@ def test_setitem_chained_no_consolidate(self):
593592
# issuecomment-361696418
594593
# chained setitem used to cause consolidation
595594
sdf = pd.SparseDataFrame([[np.nan, 1], [2, np.nan]])
596-
with pd.option_context('mode.chained_assignment', None):
597-
sdf[0][1] = 2
595+
with tm.assert_produces_warning(PerformanceWarning):
596+
with pd.option_context('mode.chained_assignment', None):
597+
sdf[0][1] = 2
598598
assert len(sdf._data.blocks) == 2
599599

600600
def test_delitem(self):
@@ -1333,24 +1333,32 @@ def spindex_kind(request):
13331333
@pytest.mark.parametrize('indexer', ['iat'])
13341334
@pytest.mark.parametrize('key', [(0, 0)])
13351335
def test_frame_assignment_at(spindex_kind, indexer, key):
1336-
_test_assignment(spindex_kind, indexer, key)
1336+
with tm.assert_produces_warning(PerformanceWarning):
1337+
_test_assignment(spindex_kind, indexer, key)
13371338

13381339

13391340
@pytest.mark.parametrize('indexer', ['at', 'loc', 'iloc'])
13401341
@pytest.mark.parametrize('key', [0,
13411342
[0, 1],
13421343
[True, False]])
13431344
def test_frame_assignment_loc(spindex_kind, indexer, key):
1344-
_test_assignment(spindex_kind, indexer, key)
1345+
with tm.assert_produces_warning(PerformanceWarning):
1346+
_test_assignment(spindex_kind, indexer, key)
13451347

13461348

13471349
@pytest.mark.parametrize('key', [None,
13481350
[True, False]])
13491351
def test_frame_assignment_setitem(spindex_kind, key):
1350-
_test_assignment(spindex_kind, None, key)
1352+
with tm.assert_produces_warning(PerformanceWarning):
1353+
_test_assignment(spindex_kind, None, key)
1354+
1355+
1356+
@pytest.mark.parametrize('key', [3])
1357+
def test_frame_assignment_extend_index_loc(spindex_kind, key):
1358+
_test_assignment(spindex_kind, 'loc', key)
13511359

13521360

1353-
@pytest.mark.parametrize('indexer', ['loc', 'at'])
13541361
@pytest.mark.parametrize('key', [3])
1355-
def test_frame_assignment_extend_index(spindex_kind, indexer, key):
1356-
_test_assignment(spindex_kind, indexer, key)
1362+
def test_frame_assignment_extend_index_at(spindex_kind, key):
1363+
with tm.assert_produces_warning(PerformanceWarning):
1364+
_test_assignment(spindex_kind, 'at', key)

pandas/tests/sparse/test_format.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pandas.compat import (is_platform_windows,
99
is_platform_32bit)
1010
from pandas.core.config import option_context
11-
11+
from pandas.errors import PerformanceWarning
1212

1313
use_32bit_repr = is_platform_windows() or is_platform_32bit()
1414

@@ -124,9 +124,10 @@ def test_sparse_repr_after_set(self):
124124
sdf = pd.SparseDataFrame([[np.nan, 1], [2, np.nan]])
125125
res = sdf.copy()
126126

127-
# Ignore the warning
128-
with pd.option_context('mode.chained_assignment', None):
129-
sdf[0][1] = 2 # This line triggers the bug
127+
with tm.assert_produces_warning(PerformanceWarning):
128+
# Ignore the warning
129+
with pd.option_context('mode.chained_assignment', None):
130+
sdf[0][1] = 2 # This line triggers the bug
130131

131132
repr(sdf)
132133
tm.assert_sp_frame_equal(sdf, res)

0 commit comments

Comments
 (0)