Skip to content

TST: unnecessary check_stacklevel=False #39901

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 1 commit into from
Feb 19, 2021
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
2 changes: 1 addition & 1 deletion pandas/tests/api/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ def test_types(self):
def test_deprecated_from_api_types(self):

for t in self.deprecated:
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
with tm.assert_produces_warning(FutureWarning):
getattr(types, t)(1)
2 changes: 1 addition & 1 deletion pandas/tests/apply/test_frame_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_transform_bad_dtype(op, frame_or_series):

# tshift is deprecated
warn = None if op != "tshift" else FutureWarning
with tm.assert_produces_warning(warn, check_stacklevel=False):
with tm.assert_produces_warning(warn):
with pytest.raises(ValueError, match=msg):
obj.transform(op)
with pytest.raises(ValueError, match=msg):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def test_astype_nansafe(val, typ):

msg = "Cannot convert NaT values to integer"
with pytest.raises(ValueError, match=msg):
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
with tm.assert_produces_warning(FutureWarning):
# datetimelike astype(int64) deprecated
astype_nansafe(arr, dtype=typ)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_getitem_boolean(
# we are producing a warning that since the passed boolean
# key is not the same as the given index, we will reindex
# not sure this is really necessary
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
with tm.assert_produces_warning(UserWarning):
indexer_obj = indexer_obj.reindex(datetime_frame.index[::-1])
subframe_obj = datetime_frame[indexer_obj]
tm.assert_frame_equal(subframe_obj, subframe)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_suppress_future_warning_with_sort_kw(sort_kw):
if sort_kw is False:
expected = expected.reindex(index=["c", "a", "b"])

with tm.assert_produces_warning(None, check_stacklevel=False):
with tm.assert_produces_warning(None):
result = a.join([b, c], how="outer", sort=sort_kw)
tm.assert_frame_equal(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_sort_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def test_sort_column_level_and_index_label(
if len(levels) > 1:
# Accessing multi-level columns that are not lexsorted raises a
# performance warning
with tm.assert_produces_warning(PerformanceWarning, check_stacklevel=False):
with tm.assert_produces_warning(PerformanceWarning):
tm.assert_frame_equal(result, expected)
else:
tm.assert_frame_equal(result, expected)
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def test_mode_sortwarning(self):
df = DataFrame({"A": [np.nan, np.nan, "a", "a"]})
expected = DataFrame({"A": ["a", np.nan]})

with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
with tm.assert_produces_warning(UserWarning):
result = df.mode(dropna=False)
result = result.sort_values(by="A").reset_index(drop=True)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_any_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_hash_error(index):

def test_copy_dtype_deprecated(index):
# GH#35853
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
with tm.assert_produces_warning(FutureWarning):
index.copy(dtype=object)


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_getitem_ndarray_3d(self, index, frame_or_series, indexer_sli):

potential_errors = (IndexError, ValueError, NotImplementedError)
with pytest.raises(potential_errors, match=msg):
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
with tm.assert_produces_warning(DeprecationWarning):
idxr[nd3]

def test_setitem_ndarray_3d(self, index, frame_or_series, indexer_sli):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_compression_warning(compression_only):
)
with tm.ensure_clean() as path:
with icom.get_handle(path, "w", compression=compression_only) as handles:
with tm.assert_produces_warning(RuntimeWarning, check_stacklevel=False):
with tm.assert_produces_warning(RuntimeWarning):
df.to_csv(handles.handle, compression=compression_only)


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ def test_mode_sortwarning(self):
expected = Series(["foo", np.nan])
s = Series([1, "foo", "foo", np.nan, np.nan])

with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
with tm.assert_produces_warning(UserWarning):
result = s.mode(dropna=False)
result = result.sort_values().reset_index(drop=True)

Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def test_to_pydatetime_nonzero_nano(self):
ts = Timestamp("2011-01-01 9:00:00.123456789")

# Warn the user of data loss (nanoseconds).
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
with tm.assert_produces_warning(UserWarning):
expected = datetime(2011, 1, 1, 9, 0, 0, 123456)
result = ts.to_pydatetime()
assert result == expected
Expand Down Expand Up @@ -541,13 +541,13 @@ def test_to_datetime_bijective(self):
# Ensure that converting to datetime and back only loses precision
# by going from nanoseconds to microseconds.
exp_warning = None if Timestamp.max.nanosecond == 0 else UserWarning
with tm.assert_produces_warning(exp_warning, check_stacklevel=False):
with tm.assert_produces_warning(exp_warning):
pydt_max = Timestamp.max.to_pydatetime()

assert Timestamp(pydt_max).value / 1000 == Timestamp.max.value / 1000

exp_warning = None if Timestamp.min.nanosecond == 0 else UserWarning
with tm.assert_produces_warning(exp_warning, check_stacklevel=False):
with tm.assert_produces_warning(exp_warning):
pydt_min = Timestamp.min.to_pydatetime()

# The next assertion can be enabled once GH#39221 is merged
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/methods/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_astype_empty_constructor_equality(self, dtype):
"m", # Generic timestamps raise a ValueError. Already tested.
):
init_empty = Series([], dtype=dtype)
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
with tm.assert_produces_warning(DeprecationWarning):
as_type_empty = Series([]).astype(dtype)
tm.assert_series_equal(init_empty, as_type_empty)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/series/methods/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_replace_with_empty_dictlike(self):
s = pd.Series(list("abcd"))
tm.assert_series_equal(s, s.replace({}))

with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
with tm.assert_produces_warning(DeprecationWarning):
empty_series = pd.Series([])
tm.assert_series_equal(s, s.replace(empty_series))

Expand Down Expand Up @@ -457,6 +457,6 @@ def test_str_replace_regex_default_raises_warning(self, pattern):
msg = r"The default value of regex will change from True to False"
if len(pattern) == 1:
msg += r".*single character regular expressions.*not.*literal strings"
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False) as w:
with tm.assert_produces_warning(FutureWarning) as w:
s.str.replace(pattern, "")
assert re.match(msg, str(w[0].message))
2 changes: 1 addition & 1 deletion pandas/tests/series/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_subclass_unstack(self):
tm.assert_frame_equal(res, exp)

def test_subclass_empty_repr(self):
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
with tm.assert_produces_warning(DeprecationWarning):
sub_series = tm.SubclassedSeries()
assert "SubclassedSeries" in repr(sub_series)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, normalize=Fals
exp_warning = UserWarning

# test nanosecond is preserved
with tm.assert_produces_warning(exp_warning, check_stacklevel=False):
with tm.assert_produces_warning(exp_warning):
result = func(ts)
assert isinstance(result, Timestamp)
if normalize is False:
Expand Down Expand Up @@ -231,7 +231,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, normalize=Fals
exp_warning = UserWarning

# test nanosecond is preserved
with tm.assert_produces_warning(exp_warning, check_stacklevel=False):
with tm.assert_produces_warning(exp_warning):
result = func(ts)
assert isinstance(result, Timestamp)
if normalize is False:
Expand Down