Skip to content

Commit 429b036

Browse files
Backport PR pandas-dev#38494: TST: don't use global fixture in the base extension tests (pandas-dev#38500)
Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent 598bd3c commit 429b036

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

pandas/_testing.py

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
+ BYTES_DTYPES
109109
)
110110

111+
NULL_OBJECTS = [None, np.nan, pd.NaT, float("nan"), pd.NA]
112+
111113

112114
# set testing_mode
113115
_testing_mode_warnings = (DeprecationWarning, ResourceWarning)

pandas/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def nselect_method(request):
266266
# ----------------------------------------------------------------
267267
# Missing values & co.
268268
# ----------------------------------------------------------------
269-
@pytest.fixture(params=[None, np.nan, pd.NaT, float("nan"), pd.NA], ids=str)
269+
@pytest.fixture(params=tm.NULL_OBJECTS, ids=str)
270270
def nulls_fixture(request):
271271
"""
272272
Fixture for each null type in pandas.

pandas/tests/extension/arrow/test_bool.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def test_view(self, data):
5151
data.view()
5252

5353
@pytest.mark.xfail(raises=AssertionError, reason="Not implemented yet")
54-
def test_contains(self, data, data_missing, nulls_fixture):
55-
super().test_contains(data, data_missing, nulls_fixture)
54+
def test_contains(self, data, data_missing):
55+
super().test_contains(data, data_missing)
5656

5757

5858
class TestConstructors(BaseArrowTests, base.BaseConstructorsTests):

pandas/tests/extension/base/interface.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_can_hold_na_valid(self, data):
2929
# GH-20761
3030
assert data._can_hold_na is True
3131

32-
def test_contains(self, data, data_missing, nulls_fixture):
32+
def test_contains(self, data, data_missing):
3333
# GH-37867
3434
# Tests for membership checks. Membership checks for nan-likes is tricky and
3535
# the settled on rule is: `nan_like in arr` is True if nan_like is
@@ -47,10 +47,12 @@ def test_contains(self, data, data_missing, nulls_fixture):
4747
assert na_value in data_missing
4848
assert na_value not in data
4949

50-
if nulls_fixture is not na_value:
51-
# the data can never contain other nan-likes than na_value
52-
assert nulls_fixture not in data
53-
assert nulls_fixture not in data_missing
50+
# the data can never contain other nan-likes than na_value
51+
for na_value_obj in tm.NULL_OBJECTS:
52+
if na_value_obj is na_value:
53+
continue
54+
assert na_value_obj not in data
55+
assert na_value_obj not in data_missing
5456

5557
def test_memory_usage(self, data):
5658
s = pd.Series(data)

pandas/tests/extension/test_categorical.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_memory_usage(self, data):
8787
# Is this deliberate?
8888
super().test_memory_usage(data)
8989

90-
def test_contains(self, data, data_missing, nulls_fixture):
90+
def test_contains(self, data, data_missing):
9191
# GH-37867
9292
# na value handling in Categorical.__contains__ is deprecated.
9393
# See base.BaseInterFaceTests.test_contains for more details.
@@ -105,9 +105,11 @@ def test_contains(self, data, data_missing, nulls_fixture):
105105
assert na_value not in data
106106

107107
# Categoricals can contain other nan-likes than na_value
108-
if nulls_fixture is not na_value:
109-
assert nulls_fixture not in data
110-
assert nulls_fixture in data_missing # this line differs from super method
108+
for na_value_obj in tm.NULL_OBJECTS:
109+
if na_value_obj is na_value:
110+
continue
111+
assert na_value_obj not in data
112+
assert na_value_obj in data_missing # this line differs from super method
111113

112114

113115
class TestConstructors(base.BaseConstructorsTests):

0 commit comments

Comments
 (0)