Skip to content

Commit 6d9a2b4

Browse files
authored
Backport PR #60553: TST: filter possible RuntimeWarning in tests (#60555)
* Backport PR #60553: TST: filter possible RuntimeWarning in tests * add more ignores
1 parent ffe0791 commit 6d9a2b4

File tree

11 files changed

+53
-0
lines changed

11 files changed

+53
-0
lines changed

pandas/tests/extension/test_interval.py

+25
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,31 @@ def _supports_reduction(self, ser: pd.Series, op_name: str) -> bool:
9090
def test_fillna_length_mismatch(self, data_missing):
9191
super().test_fillna_length_mismatch(data_missing)
9292

93+
@pytest.mark.filterwarnings(
94+
"ignore:invalid value encountered in cast:RuntimeWarning"
95+
)
96+
def test_hash_pandas_object(self, data):
97+
super().test_hash_pandas_object(data)
98+
99+
@pytest.mark.filterwarnings(
100+
"ignore:invalid value encountered in cast:RuntimeWarning"
101+
)
102+
def test_hash_pandas_object_works(self, data, as_frame):
103+
super().test_hash_pandas_object_works(data, as_frame)
104+
105+
@pytest.mark.filterwarnings(
106+
"ignore:invalid value encountered in cast:RuntimeWarning"
107+
)
108+
@pytest.mark.parametrize("engine", ["c", "python"])
109+
def test_EA_types(self, engine, data, request):
110+
super().test_EA_types(engine, data, request)
111+
112+
@pytest.mark.filterwarnings(
113+
"ignore:invalid value encountered in cast:RuntimeWarning"
114+
)
115+
def test_astype_str(self, data):
116+
super().test_astype_str(data)
117+
93118

94119
# TODO: either belongs in tests.arrays.interval or move into base tests.
95120
def test_fillna_non_scalar_raises(data_missing):

pandas/tests/frame/methods/test_to_numpy.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import pytest
23

34
import pandas.util._test_decorators as td
45

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

45+
@pytest.mark.filterwarnings(
46+
"ignore:invalid value encountered in cast:RuntimeWarning"
47+
)
4448
def test_to_numpy_mixed_dtype_to_str(self):
4549
# https://github.com/pandas-dev/pandas/issues/35455
4650
df = DataFrame([[Timestamp("2020-01-01 00:00:00"), 100.0]])

pandas/tests/frame/test_constructors.py

+3
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,9 @@ def test_construct_with_two_categoricalindex_series(self):
24502450
)
24512451
tm.assert_frame_equal(result, expected)
24522452

2453+
@pytest.mark.filterwarnings(
2454+
"ignore:invalid value encountered in cast:RuntimeWarning"
2455+
)
24532456
def test_constructor_series_nonexact_categoricalindex(self):
24542457
# GH 42424
24552458
ser = Series(range(100))

pandas/tests/groupby/test_categorical.py

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def f(a):
6767
}
6868

6969

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

@@ -338,6 +339,7 @@ def test_apply(ordered):
338339
tm.assert_series_equal(result, expected)
339340

340341

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

15581560

1561+
@pytest.mark.filterwarnings("ignore:invalid value encountered in cast:RuntimeWarning")
15591562
def test_series_groupby_categorical_aggregation_getitem():
15601563
# GH 8870
15611564
d = {"foo": [10, 8, 4, 1], "bar": [10, 20, 30, 40], "baz": ["d", "c", "d", "c"]}

pandas/tests/groupby/test_groupby.py

+1
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,7 @@ def test_groupby_numeric_only_std_no_result(numeric_only):
31183118
dfgb.std(numeric_only=numeric_only)
31193119

31203120

3121+
@pytest.mark.filterwarnings("ignore:invalid value encountered in cast:RuntimeWarning")
31213122
def test_grouping_with_categorical_interval_columns():
31223123
# GH#34164
31233124
df = DataFrame({"x": [0.1, 0.2, 0.3, -0.4, 0.5], "w": ["a", "b", "a", "c", "a"]})

pandas/tests/indexes/interval/test_astype.py

+6
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ def test_subtype_datetimelike(self, index, subtype):
186186
with pytest.raises(TypeError, match=msg):
187187
index.astype(dtype)
188188

189+
@pytest.mark.filterwarnings(
190+
"ignore:invalid value encountered in cast:RuntimeWarning"
191+
)
192+
def test_astype_category(self, index):
193+
super().test_astype_category(index)
194+
189195

190196
class TestDatetimelikeSubtype(AstypeTests):
191197
"""Tests specific to IntervalIndex with datetime-like subtype"""

pandas/tests/indexes/interval/test_formats.py

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def test_repr_floats(self):
5959
expected = "(329.973, 345.137] 1\n(345.137, 360.191] 2\ndtype: int64"
6060
assert result == expected
6161

62+
@pytest.mark.filterwarnings(
63+
"ignore:invalid value encountered in cast:RuntimeWarning"
64+
)
6265
@pytest.mark.parametrize(
6366
"tuples, closed, expected_data",
6467
[

pandas/tests/indexes/interval/test_indexing.py

+3
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ def test_get_indexer_categorical(self, target, ordered):
341341
expected = index.get_indexer(target)
342342
tm.assert_numpy_array_equal(result, expected)
343343

344+
@pytest.mark.filterwarnings(
345+
"ignore:invalid value encountered in cast:RuntimeWarning"
346+
)
344347
def test_get_indexer_categorical_with_nans(self):
345348
# GH#41934 nans in both index and in target
346349
ii = IntervalIndex.from_breaks(range(5))

pandas/tests/indexes/test_setops.py

+1
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ def test_intersection_difference_match_empty(self, index, sort):
519519
tm.assert_index_equal(inter, diff, exact=True)
520520

521521

522+
@pytest.mark.filterwarnings("ignore:invalid value encountered in cast:RuntimeWarning")
522523
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
523524
@pytest.mark.parametrize(
524525
"method", ["intersection", "union", "difference", "symmetric_difference"]

pandas/tests/io/excel/test_writers.py

+3
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,9 @@ def test_excel_date_datetime_format(self, ext, path):
755755
# we need to use df_expected to check the result.
756756
tm.assert_frame_equal(rs2, df_expected)
757757

758+
@pytest.mark.filterwarnings(
759+
"ignore:invalid value encountered in cast:RuntimeWarning"
760+
)
758761
def test_to_excel_interval_no_labels(self, path, using_infer_string):
759762
# see gh-19242
760763
#

pandas/tests/reshape/test_cut.py

+1
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ def test_cut_with_duplicated_index_lowest_included():
727727
tm.assert_series_equal(result, expected)
728728

729729

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

0 commit comments

Comments
 (0)