Skip to content

TST: fix usage of assert_produces_warning #10701

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
Show file tree
Hide file tree
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
21 changes: 7 additions & 14 deletions pandas/io/tests/test_stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down