Skip to content

test: updates tests from pandas with compliance issues #365

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 7 commits into from
Jun 12, 2025
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
59 changes: 56 additions & 3 deletions tests/compliance/date/test_date_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ class TestDtype(base.BaseDtypeTests):


class TestGetitem(base.BaseGetitemTests):
pass
def test_take_pandas_style_negative_raises(self, data, na_value):
# This test was failing compliance checks because it attempted to match
# a pytest regex match using an empty string (""), which pytest version
# 8.4.0 stopped allowing.
# The test has been updated in pandas main so that it will
# no longer fail, but the fix is not expected to be released until
# at least pandas version 3.0 (current version is 2.3).
with pytest.raises(ValueError):
data.take([0, -2], fill_value=na_value, allow_fill=True)


class TestGroupby(base.BaseGroupbyTests):
Expand All @@ -63,7 +71,26 @@ class TestIndex(base.BaseIndexTests):


class TestInterface(base.BaseInterfaceTests):
pass
def test_array_interface_copy(self, data):
# This test was failing compliance checks due to changes in how
# numpy handles processing when np.array(obj, copy=False).
# Until pandas changes the existing tests, this compliance test
# will continue to fail.
import numpy as np
from pandas.compat.numpy import np_version_gt2

result_copy1 = np.array(data, copy=True)
result_copy2 = np.array(data, copy=True)
assert not np.may_share_memory(result_copy1, result_copy2)

if not np_version_gt2:
# copy=False semantics are only supported in NumPy>=2.
return

with pytest.raises(ValueError):
result_nocopy1 = np.array(data, copy=False)
result_nocopy2 = np.array(data, copy=False)
assert np.may_share_memory(result_nocopy1, result_nocopy2)


class TestMissing(base.BaseMissingTests):
Expand Down Expand Up @@ -102,6 +129,21 @@ def test_hash_pandas_object(self):
further investigation. See issues 182, 183, 185."""
)

def test_argmax_argmin_no_skipna_notimplemented(self, data_missing_for_sorting):
# This test was failing compliance checks because it attempted to match
# a pytest regex match using an empty string (""), which pytest version
# 8.4.0 stopped allowing.
# The test has been updated in pandas main so that it will
# no longer fail, but the fix is not expected to be released until
# at least pandas version 3.0 (current version is 2.3)
data = data_missing_for_sorting

with pytest.raises(NotImplementedError):
data.argmin(skipna=False)

with pytest.raises(NotImplementedError):
data.argmax(skipna=False)


class TestParsing(base.BaseParsingTests):
pass
Expand All @@ -116,7 +158,18 @@ class TestReshaping(base.BaseReshapingTests):


class TestSetitem(base.BaseSetitemTests):
pass
# This test was failing compliance checks because it attempted to match
# a pytest regex match using an empty string (""), which pytest version
# 8.4.0 stopped allowing.
# The test has been updated in pandas main so that it will
# no longer fail, but the fix is not expected to be released until
# at least pandas version 3.0 (current version is 2.3).
def test_setitem_invalid(self, data, invalid_scalar):
with pytest.raises((ValueError, TypeError)):
data[0] = invalid_scalar

with pytest.raises((ValueError, TypeError)):
data[:] = invalid_scalar


# NDArrayBacked2DTests suite added in https://github.com/pandas-dev/pandas/pull/44974
Expand Down
73 changes: 72 additions & 1 deletion tests/compliance/json/test_json_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ def test_getitem_scalar(self, data):
"""
super().test_getitem_scalar(data)

def test_take_pandas_style_negative_raises(self, data, na_value):
# This test was failing compliance checks because it attempted to match
# a pytest regex match using an empty string (""), which pytest version
# 8.4.0 stopped allowing.
# The test has been updated in pandas main so that it will
# no longer fail, but the fix is not expected to be released until
# at least pandas version 3.0 (current version is 2.3).
with pytest.raises(ValueError):
data.take([0, -2], fill_value=na_value, allow_fill=True)


class TestJSONArrayIndex(base.BaseIndexTests):
pass
Expand All @@ -133,6 +143,26 @@ def test_array_interface(self, data):
def test_view(self, data):
super().test_view(data)

def test_array_interface_copy(self, data):
# This test was failing compliance checks due to changes in how
# numpy handles processing when np.array(obj, copy=False).
# Until pandas changes the existing tests, this compliance test
# will continue to fail.
import numpy as np
from pandas.compat.numpy import np_version_gt2

result_copy1 = np.array(data, copy=True)
result_copy2 = np.array(data, copy=True)
assert not np.may_share_memory(result_copy1, result_copy2)

if not np_version_gt2:
# copy=False semantics are only supported in NumPy>=2.
return

result_nocopy1 = np.array(data, copy=False)
result_nocopy2 = np.array(data, copy=False)
assert not np.may_share_memory(result_nocopy1, result_nocopy2)


class TestJSONArrayParsing(base.BaseParsingTests):
@pytest.mark.xfail(reason="data type 'json' not understood")
Expand Down Expand Up @@ -190,6 +220,21 @@ def test_sort_values(self, data_for_sorting):
def test_sort_values_frame(self, data_for_sorting):
super().test_sort_values_frame(data_for_sorting)

def test_argmax_argmin_no_skipna_notimplemented(self, data_missing_for_sorting):
# This test was failing compliance checks because it attempted to match
# a pytest regex match using an empty string (""), which pytest version
# 8.4.0 stopped allowing.
# The test has been updated in pandas main so that it will
# no longer fail, but the fix is not expected to be released until
# at least pandas version 3.0 (current version is 2.3)
data = data_missing_for_sorting

with pytest.raises(NotImplementedError):
data.argmin(skipna=False)

with pytest.raises(NotImplementedError):
data.argmax(skipna=False)


class TestJSONArrayMissing(base.BaseMissingTests):
@pytest.mark.xfail(reason="Setting a dict as a scalar")
Expand Down Expand Up @@ -239,7 +284,20 @@ class TestJSONArrayPrinting(base.BasePrintingTests):


class TestJSONArrayReduce(base.BaseReduceTests):
pass
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna):
op_name = all_numeric_reductions
ser = pd.Series(data)

if not self._supports_reduction(ser, op_name):
# Sum does not raise an Error (TypeError or otherwise)
if op_name != "sum":
with pytest.raises(TypeError):
getattr(ser, op_name)(skipna=skipna)
else:
# min/max with empty produce numpy warnings
self.check_reduce(ser, op_name, skipna)


class TestJSONArrayReshaping(base.BaseReshapingTests):
Expand Down Expand Up @@ -356,6 +414,19 @@ def test_setitem_mask_boolean_array_with_na(self, data, box_in_series):
def test_setitem_preserves_views(self, data):
super().test_setitem_preserves_views(data)

def test_setitem_invalid(self, data, invalid_scalar):
# This test was failing compliance checks because it attempted to match
# a pytest regex match using an empty string (""), which pytest version
# 8.4.0 stopped allowing.
# The test has been updated in pandas main so that it will
# no longer fail, but the fix is not expected to be released until
# at least pandas version 3.0 (current version is 2.3)
with pytest.raises((ValueError, TypeError)):
data[0] = invalid_scalar

with pytest.raises((ValueError, TypeError)):
data[:] = invalid_scalar


class TestJSONArrayDim2Compat(base.Dim2CompatTests):
pass
59 changes: 56 additions & 3 deletions tests/compliance/time/test_time_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ class TestDtype(base.BaseDtypeTests):


class TestGetitem(base.BaseGetitemTests):
pass
def test_take_pandas_style_negative_raises(self, data, na_value):
# This test was failing compliance checks because it attempted to match
# a pytest regex match using an empty string (""), which pytest version
# 8.4.0 stopped allowing.
# The test has been updated in pandas main so that it will
# no longer fail, but the fix is not expected to be released until
# at least pandas version 3.0 (current version is 2.3).
with pytest.raises(ValueError):
data.take([0, -2], fill_value=na_value, allow_fill=True)


class TestGroupby(base.BaseGroupbyTests):
Expand All @@ -68,7 +76,26 @@ class TestIndex(base.BaseIndexTests):


class TestInterface(base.BaseInterfaceTests):
pass
def test_array_interface_copy(self, data):
# This test was failing compliance checks due to changes in how
# numpy handles processing when np.array(obj, copy=False).
# Until pandas changes the existing tests, this compliance test
# will continue to fail.
import numpy as np
from pandas.compat.numpy import np_version_gt2

result_copy1 = np.array(data, copy=True)
result_copy2 = np.array(data, copy=True)
assert not np.may_share_memory(result_copy1, result_copy2)

if not np_version_gt2:
# copy=False semantics are only supported in NumPy>=2.
return

with pytest.raises(ValueError):
result_nocopy1 = np.array(data, copy=False)
result_nocopy2 = np.array(data, copy=False)
assert np.may_share_memory(result_nocopy1, result_nocopy2)


class TestMissing(base.BaseMissingTests):
Expand All @@ -95,6 +122,21 @@ def test_value_counts(self, all_data, dropna):

tm.assert_series_equal(result, expected)

def test_argmax_argmin_no_skipna_notimplemented(self, data_missing_for_sorting):
# This test was failing compliance checks because it attempted to match
# a pytest regex match using an empty string (""), which pytest version
# 8.4.0 stopped allowing.
# The test has been updated in pandas main so that it will
# no longer fail, but the fix is not expected to be released until
# at least pandas version 3.0 (current version is 2.3)
data = data_missing_for_sorting

with pytest.raises(NotImplementedError):
data.argmin(skipna=False)

with pytest.raises(NotImplementedError):
data.argmax(skipna=False)


class TestParsing(base.BaseParsingTests):
pass
Expand All @@ -109,4 +151,15 @@ class TestReshaping(base.BaseReshapingTests):


class TestSetitem(base.BaseSetitemTests):
pass
def test_setitem_invalid(self, data, invalid_scalar):
# This test was failing compliance checks because it attempted to match
# a pytest regex match using an empty string (""), which pytest version
# 8.4.0 stopped allowing.
# The test has been updated in pandas main so that it will
# no longer fail, but the fix is not expected to be released until
# at least pandas version 3.0 (current version is 2.3)
with pytest.raises((ValueError, TypeError)):
data[0] = invalid_scalar

with pytest.raises((ValueError, TypeError)):
data[:] = invalid_scalar