Skip to content

Backport PR #38494 on branch 1.2.x (TST: don't use global fixture in the base extension tests) #38500

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
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: 2 additions & 0 deletions pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
+ BYTES_DTYPES
)

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


# set testing_mode
_testing_mode_warnings = (DeprecationWarning, ResourceWarning)
Expand Down
2 changes: 1 addition & 1 deletion pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def nselect_method(request):
# ----------------------------------------------------------------
# Missing values & co.
# ----------------------------------------------------------------
@pytest.fixture(params=[None, np.nan, pd.NaT, float("nan"), pd.NA], ids=str)
@pytest.fixture(params=tm.NULL_OBJECTS, ids=str)
def nulls_fixture(request):
"""
Fixture for each null type in pandas.
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/arrow/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def test_view(self, data):
data.view()

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


class TestConstructors(BaseArrowTests, base.BaseConstructorsTests):
Expand Down
12 changes: 7 additions & 5 deletions pandas/tests/extension/base/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_can_hold_na_valid(self, data):
# GH-20761
assert data._can_hold_na is True

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

if nulls_fixture is not na_value:
# the data can never contain other nan-likes than na_value
assert nulls_fixture not in data
assert nulls_fixture not in data_missing
# the data can never contain other nan-likes than na_value
for na_value_obj in tm.NULL_OBJECTS:
if na_value_obj is na_value:
continue
assert na_value_obj not in data
assert na_value_obj not in data_missing

def test_memory_usage(self, data):
s = pd.Series(data)
Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_memory_usage(self, data):
# Is this deliberate?
super().test_memory_usage(data)

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

# Categoricals can contain other nan-likes than na_value
if nulls_fixture is not na_value:
assert nulls_fixture not in data
assert nulls_fixture in data_missing # this line differs from super method
for na_value_obj in tm.NULL_OBJECTS:
if na_value_obj is na_value:
continue
assert na_value_obj not in data
assert na_value_obj in data_missing # this line differs from super method


class TestConstructors(base.BaseConstructorsTests):
Expand Down