Skip to content

TST: Fix test warnings #47257

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 10 commits into from
Jun 8, 2022
8 changes: 4 additions & 4 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2007,11 +2007,11 @@ def test_bool_frame_mult_float():
tm.assert_frame_equal(result, expected)


def test_frame_sub_nullable_int(any_int_dtype):
def test_frame_sub_nullable_int(any_int_ea_dtype):
# GH 32822
series1 = Series([1, 2, np.nan], dtype=any_int_dtype)
series2 = Series([1, 2, 3], dtype=any_int_dtype)
expected = DataFrame([0, 0, np.nan], dtype=any_int_dtype)
series1 = Series([1, 2, None], dtype=any_int_ea_dtype)
series2 = Series([1, 2, 3], dtype=any_int_ea_dtype)
expected = DataFrame([0, 0, None], dtype=any_int_ea_dtype)
result = series1.to_frame() - series2.to_frame()
tm.assert_frame_equal(result, expected)

Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,8 @@ def check_views(c_only: bool = False):

# FIXME(GH#35417): until GH#35417, iloc.setitem into EA values does not preserve
# view, so we have to check in the other direction
df.iloc[:, 2] = pd.array([45, 46], dtype=c.dtype)
with tm.assert_produces_warning(FutureWarning, match="will attempt to set"):
df.iloc[:, 2] = pd.array([45, 46], dtype=c.dtype)
assert df.dtypes.iloc[2] == c.dtype
if not copy:
check_views(True)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/groupby/aggregate/test_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def incorrect_function(values, index):


@td.skip_if_no("numba")
@pytest.mark.filterwarnings("ignore:\n")
@pytest.mark.filterwarnings("ignore")
# Filter warnings when parallel=True and the function can't be parallelized by Numba
@pytest.mark.parametrize("jit", [True, False])
@pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"])
Expand Down Expand Up @@ -76,7 +76,7 @@ def func_numba(values, index):


@td.skip_if_no("numba")
@pytest.mark.filterwarnings("ignore:\n")
@pytest.mark.filterwarnings("ignore")
# Filter warnings when parallel=True and the function can't be parallelized by Numba
@pytest.mark.parametrize("jit", [True, False])
@pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"])
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@td.skip_if_no("numba")
@pytest.mark.filterwarnings("ignore:\n")
@pytest.mark.filterwarnings("ignore")
# Filter warnings when parallel=True and the function can't be parallelized by Numba
class TestEngine:
def test_cython_vs_numba_frame(
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/groupby/transform/test_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def incorrect_function(values, index):


@td.skip_if_no("numba")
@pytest.mark.filterwarnings("ignore:\n")
@pytest.mark.filterwarnings("ignore")
# Filter warnings when parallel=True and the function can't be parallelized by Numba
@pytest.mark.parametrize("jit", [True, False])
@pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"])
Expand Down Expand Up @@ -73,7 +73,7 @@ def func(values, index):


@td.skip_if_no("numba")
@pytest.mark.filterwarnings("ignore:\n")
@pytest.mark.filterwarnings("ignore")
# Filter warnings when parallel=True and the function can't be parallelized by Numba
@pytest.mark.parametrize("jit", [True, False])
@pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"])
Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/io/parser/test_parse_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,12 @@ def test_date_parser_resolution_if_not_ns(all_parsers):
"""

def date_parser(dt, time):
return np.array(dt + "T" + time, dtype="datetime64[s]")
try:
arr = dt + "T" + time
except TypeError:
# dt & time are date/time objects
arr = [datetime.combine(d, t) for d, t in zip(dt, time)]
return np.array(arr, dtype="datetime64[s]")

result = parser.read_csv(
StringIO(data),
Expand Down
30 changes: 25 additions & 5 deletions pandas/tests/strings/test_find_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ def test_contains(any_string_dtype):
values = Series(values, dtype=any_string_dtype)
pat = "mmm[_]+"

result = values.str.contains(pat)
with tm.maybe_produces_warning(
PerformanceWarning,
any_string_dtype == "string[pyarrow]" and pa_version_under4p0,
):
result = values.str.contains(pat)
expected_dtype = "object" if any_string_dtype == "object" else "boolean"
expected = Series(
np.array([False, np.nan, True, True, False], dtype=np.object_),
Expand Down Expand Up @@ -88,7 +92,11 @@ def test_contains(any_string_dtype):
)
tm.assert_series_equal(result, expected)

result = values.str.contains(pat, na=False)
with tm.maybe_produces_warning(
PerformanceWarning,
any_string_dtype == "string[pyarrow]" and pa_version_under4p0,
):
result = values.str.contains(pat, na=False)
expected_dtype = np.bool_ if any_string_dtype == "object" else "boolean"
expected = Series(np.array([False, False, True, True]), dtype=expected_dtype)
tm.assert_series_equal(result, expected)
Expand Down Expand Up @@ -181,7 +189,11 @@ def test_contains_moar(any_string_dtype):
dtype=any_string_dtype,
)

result = s.str.contains("a")
with tm.maybe_produces_warning(
PerformanceWarning,
any_string_dtype == "string[pyarrow]" and pa_version_under4p0,
):
result = s.str.contains("a")
expected_dtype = "object" if any_string_dtype == "object" else "boolean"
expected = Series(
[False, False, False, True, True, False, np.nan, False, False, True],
Expand Down Expand Up @@ -619,7 +631,11 @@ def test_replace_moar(any_string_dtype):
dtype=any_string_dtype,
)

result = ser.str.replace("A", "YYY")
with tm.maybe_produces_warning(
PerformanceWarning,
any_string_dtype == "string[pyarrow]" and pa_version_under4p0,
):
result = ser.str.replace("A", "YYY")
expected = Series(
["YYY", "B", "C", "YYYaba", "Baca", "", np.nan, "CYYYBYYY", "dog", "cat"],
dtype=any_string_dtype,
Expand Down Expand Up @@ -727,7 +743,11 @@ def test_replace_regex_single_character(regex, any_string_dtype):
):
result = s.str.replace(".", "a", regex=regex)
else:
result = s.str.replace(".", "a", regex=regex)
with tm.maybe_produces_warning(
PerformanceWarning,
any_string_dtype == "string[pyarrow]" and pa_version_under4p0,
):
result = s.str.replace(".", "a", regex=regex)

expected = Series(["aab", "a", "b", np.nan, ""], dtype=any_string_dtype)
tm.assert_series_equal(result, expected)
Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/strings/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,11 @@ def test_slice_replace(start, stop, repl, expected, any_string_dtype):
def test_strip_lstrip_rstrip(any_string_dtype, method, exp):
ser = Series([" aa ", " bb \n", np.nan, "cc "], dtype=any_string_dtype)

result = getattr(ser.str, method)()
with tm.maybe_produces_warning(
PerformanceWarning,
any_string_dtype == "string[pyarrow]" and pa_version_under4p0,
):
result = getattr(ser.str, method)()
expected = Series(exp, dtype=any_string_dtype)
tm.assert_series_equal(result, expected)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/window/test_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def arithmetic_numba_supported_operators(request):


@td.skip_if_no("numba")
@pytest.mark.filterwarnings("ignore:\n")
@pytest.mark.filterwarnings("ignore")
# Filter warnings when parallel=True and the function can't be parallelized by Numba
class TestEngine:
@pytest.mark.parametrize("jit", [True, False])
Expand Down Expand Up @@ -331,7 +331,7 @@ def test_invalid_kwargs_nopython():

@td.skip_if_no("numba")
@pytest.mark.slow
@pytest.mark.filterwarnings("ignore:\n")
@pytest.mark.filterwarnings("ignore")
# Filter warnings when parallel=True and the function can't be parallelized by Numba
class TestTableMethod:
def test_table_series_valueerror(self):
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/window/test_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@


@td.skip_if_no("numba")
@pytest.mark.filterwarnings("ignore:\n")
@pytest.mark.filterwarnings("ignore")
# Filter warnings when parallel=True and the function can't be parallelized by Numba
class TestEWM:
def test_invalid_update(self):
df = DataFrame({"a": range(5), "b": range(5)})
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ filterwarnings = [
"ignore:pandas.util.testing is deprecated:FutureWarning:importlib",
# Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758
"ignore:`np.MachAr` is deprecated:DeprecationWarning:numba",

]
junit_family = "xunit2"
markers = [
Expand Down