From c0b43fab91ac2fb08b1b824a2ee829c0fabba397 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 30 Jul 2015 11:13:26 +0200 Subject: [PATCH] TST: fix usage of assert_produces_warning --- pandas/io/tests/test_stata.py | 21 +++++++-------------- pandas/tests/test_indexing.py | 9 ++++++--- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pandas/io/tests/test_stata.py b/pandas/io/tests/test_stata.py index cc9ab977241f9..ca05eda20b0a8 100644 --- a/pandas/io/tests/test_stata.py +++ b/pandas/io/tests/test_stata.py @@ -464,7 +464,7 @@ def test_timestamp_and_label(self): data_label = 'This is a data file.' with tm.ensure_clean() as path: original.to_stata(path, time_stamp=time_stamp, data_label=data_label) - + with StataReader(path) as reader: parsed_time_stamp = dt.datetime.strptime(reader.time_stamp, ('%d %b %Y %H:%M')) assert parsed_time_stamp == time_stamp @@ -475,10 +475,8 @@ def test_numeric_column_names(self): original.index.name = 'index' with tm.ensure_clean() as path: # should get a warning for that format. - with warnings.catch_warnings(record=True) as w: - tm.assert_produces_warning(original.to_stata(path), InvalidColumnName) - # should produce a single warning - tm.assert_equal(len(w), 1) + with tm.assert_produces_warning(InvalidColumnName): + original.to_stata(path) written_and_read_again = self.read_dta(path) written_and_read_again = written_and_read_again.set_index('index') @@ -530,11 +528,8 @@ def test_large_value_conversion(self): original = DataFrame({'s0': s0, 's1': s1, 's2': s2, 's3': s3}) original.index.name = 'index' with tm.ensure_clean() as path: - with warnings.catch_warnings(record=True) as w: - tm.assert_produces_warning(original.to_stata(path), - PossiblePrecisionLoss) - # should produce a single warning - tm.assert_equal(len(w), 1) + with tm.assert_produces_warning(PossiblePrecisionLoss): + original.to_stata(path) written_and_read_again = self.read_dta(path) modified = original.copy() @@ -548,10 +543,8 @@ def test_dates_invalid_column(self): original = DataFrame([datetime(2006, 11, 19, 23, 13, 20)]) original.index.name = 'index' with tm.ensure_clean() as path: - with warnings.catch_warnings(record=True) as w: - tm.assert_produces_warning(original.to_stata(path, {0: 'tc'}), - InvalidColumnName) - tm.assert_equal(len(w), 1) + with tm.assert_produces_warning(InvalidColumnName): + original.to_stata(path, {0: 'tc'}) written_and_read_again = self.read_dta(path) modified = original.copy() diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 624fa11ac908a..3ba58d7208474 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -4103,9 +4103,12 @@ def test_slice_indexer(self): def check_iloc_compat(s): # invalid type for iloc (but works with a warning) - self.assert_produces_warning(FutureWarning, lambda : s.iloc[6.0:8]) - self.assert_produces_warning(FutureWarning, lambda : s.iloc[6.0:8.0]) - self.assert_produces_warning(FutureWarning, lambda : s.iloc[6:8.0]) + with self.assert_produces_warning(FutureWarning): + s.iloc[6.0:8] + with self.assert_produces_warning(FutureWarning): + s.iloc[6.0:8.0] + with self.assert_produces_warning(FutureWarning): + s.iloc[6:8.0] def check_slicing_positional(index):