Skip to content

Commit

Permalink
Backport PR #60553: TST: filter possible RuntimeWarning in tests (#60555
Browse files Browse the repository at this point in the history
)

* Backport PR #60553: TST: filter possible RuntimeWarning in tests

* add more ignores
  • Loading branch information
mroeschke authored Dec 13, 2024
1 parent ffe0791 commit 6d9a2b4
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pandas/tests/extension/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ def _supports_reduction(self, ser: pd.Series, op_name: str) -> bool:
def test_fillna_length_mismatch(self, data_missing):
super().test_fillna_length_mismatch(data_missing)

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
def test_hash_pandas_object(self, data):
super().test_hash_pandas_object(data)

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
def test_hash_pandas_object_works(self, data, as_frame):
super().test_hash_pandas_object_works(data, as_frame)

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
@pytest.mark.parametrize("engine", ["c", "python"])
def test_EA_types(self, engine, data, request):
super().test_EA_types(engine, data, request)

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
def test_astype_str(self, data):
super().test_astype_str(data)


# TODO: either belongs in tests.arrays.interval or move into base tests.
def test_fillna_non_scalar_raises(data_missing):
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/frame/methods/test_to_numpy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

import pandas.util._test_decorators as td

Expand Down Expand Up @@ -41,6 +42,9 @@ def test_to_numpy_copy(self, using_copy_on_write):
else:
assert df.to_numpy(copy=False, na_value=np.nan).base is arr

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
def test_to_numpy_mixed_dtype_to_str(self):
# https://github.com/pandas-dev/pandas/issues/35455
df = DataFrame([[Timestamp("2020-01-01 00:00:00"), 100.0]])
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,9 @@ def test_construct_with_two_categoricalindex_series(self):
)
tm.assert_frame_equal(result, expected)

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
def test_constructor_series_nonexact_categoricalindex(self):
# GH 42424
ser = Series(range(100))
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def f(a):
}


@pytest.mark.filterwarnings("ignore:invalid value encountered in cast:RuntimeWarning")
def test_apply_use_categorical_name(df):
cats = qcut(df.C, 4)

Expand Down Expand Up @@ -338,6 +339,7 @@ def test_apply(ordered):
tm.assert_series_equal(result, expected)


@pytest.mark.filterwarnings("ignore:invalid value encountered in cast:RuntimeWarning")
def test_observed(request, using_infer_string, observed):
# multiple groupers, don't re-expand the output space
# of the grouper
Expand Down Expand Up @@ -1556,6 +1558,7 @@ def test_dataframe_groupby_on_2_categoricals_when_observed_is_false(
assert (res.loc[unobserved_cats] == expected).all().all()


@pytest.mark.filterwarnings("ignore:invalid value encountered in cast:RuntimeWarning")
def test_series_groupby_categorical_aggregation_getitem():
# GH 8870
d = {"foo": [10, 8, 4, 1], "bar": [10, 20, 30, 40], "baz": ["d", "c", "d", "c"]}
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3118,6 +3118,7 @@ def test_groupby_numeric_only_std_no_result(numeric_only):
dfgb.std(numeric_only=numeric_only)


@pytest.mark.filterwarnings("ignore:invalid value encountered in cast:RuntimeWarning")
def test_grouping_with_categorical_interval_columns():
# GH#34164
df = DataFrame({"x": [0.1, 0.2, 0.3, -0.4, 0.5], "w": ["a", "b", "a", "c", "a"]})
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/indexes/interval/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def test_subtype_datetimelike(self, index, subtype):
with pytest.raises(TypeError, match=msg):
index.astype(dtype)

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
def test_astype_category(self, index):
super().test_astype_category(index)


class TestDatetimelikeSubtype(AstypeTests):
"""Tests specific to IntervalIndex with datetime-like subtype"""
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/indexes/interval/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def test_repr_floats(self):
expected = "(329.973, 345.137] 1\n(345.137, 360.191] 2\ndtype: int64"
assert result == expected

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
@pytest.mark.parametrize(
"tuples, closed, expected_data",
[
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/indexes/interval/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ def test_get_indexer_categorical(self, target, ordered):
expected = index.get_indexer(target)
tm.assert_numpy_array_equal(result, expected)

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
def test_get_indexer_categorical_with_nans(self):
# GH#41934 nans in both index and in target
ii = IntervalIndex.from_breaks(range(5))
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/indexes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ def test_intersection_difference_match_empty(self, index, sort):
tm.assert_index_equal(inter, diff, exact=True)


@pytest.mark.filterwarnings("ignore:invalid value encountered in cast:RuntimeWarning")
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
@pytest.mark.parametrize(
"method", ["intersection", "union", "difference", "symmetric_difference"]
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/io/excel/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,9 @@ def test_excel_date_datetime_format(self, ext, path):
# we need to use df_expected to check the result.
tm.assert_frame_equal(rs2, df_expected)

@pytest.mark.filterwarnings(
"ignore:invalid value encountered in cast:RuntimeWarning"
)
def test_to_excel_interval_no_labels(self, path, using_infer_string):
# see gh-19242
#
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/reshape/test_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ def test_cut_with_duplicated_index_lowest_included():
tm.assert_series_equal(result, expected)


@pytest.mark.filterwarnings("ignore:invalid value encountered in cast:RuntimeWarning")
def test_cut_with_nonexact_categorical_indices():
# GH 42424

Expand Down

0 comments on commit 6d9a2b4

Please sign in to comment.