Skip to content

Commit 9410076

Browse files
test: updates tests from pandas with compliance issues (#365)
* test: updates tests with regex matches * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * updates to np.array processing * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * update imports * update docstrings * update docstrings --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent a7e18a2 commit 9410076

File tree

3 files changed

+184
-7
lines changed

3 files changed

+184
-7
lines changed

tests/compliance/date/test_date_compliance.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ class TestDtype(base.BaseDtypeTests):
5151

5252

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

5664

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

6472

6573
class TestInterface(base.BaseInterfaceTests):
66-
pass
74+
def test_array_interface_copy(self, data):
75+
# This test was failing compliance checks due to changes in how
76+
# numpy handles processing when np.array(obj, copy=False).
77+
# Until pandas changes the existing tests, this compliance test
78+
# will continue to fail.
79+
import numpy as np
80+
from pandas.compat.numpy import np_version_gt2
81+
82+
result_copy1 = np.array(data, copy=True)
83+
result_copy2 = np.array(data, copy=True)
84+
assert not np.may_share_memory(result_copy1, result_copy2)
85+
86+
if not np_version_gt2:
87+
# copy=False semantics are only supported in NumPy>=2.
88+
return
89+
90+
with pytest.raises(ValueError):
91+
result_nocopy1 = np.array(data, copy=False)
92+
result_nocopy2 = np.array(data, copy=False)
93+
assert np.may_share_memory(result_nocopy1, result_nocopy2)
6794

6895

6996
class TestMissing(base.BaseMissingTests):
@@ -102,6 +129,21 @@ def test_hash_pandas_object(self):
102129
further investigation. See issues 182, 183, 185."""
103130
)
104131

132+
def test_argmax_argmin_no_skipna_notimplemented(self, data_missing_for_sorting):
133+
# This test was failing compliance checks because it attempted to match
134+
# a pytest regex match using an empty string (""), which pytest version
135+
# 8.4.0 stopped allowing.
136+
# The test has been updated in pandas main so that it will
137+
# no longer fail, but the fix is not expected to be released until
138+
# at least pandas version 3.0 (current version is 2.3)
139+
data = data_missing_for_sorting
140+
141+
with pytest.raises(NotImplementedError):
142+
data.argmin(skipna=False)
143+
144+
with pytest.raises(NotImplementedError):
145+
data.argmax(skipna=False)
146+
105147

106148
class TestParsing(base.BaseParsingTests):
107149
pass
@@ -116,7 +158,18 @@ class TestReshaping(base.BaseReshapingTests):
116158

117159

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

121174

122175
# NDArrayBacked2DTests suite added in https://github.com/pandas-dev/pandas/pull/44974

tests/compliance/json/test_json_compliance.py

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ def test_getitem_scalar(self, data):
107107
"""
108108
super().test_getitem_scalar(data)
109109

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

111121
class TestJSONArrayIndex(base.BaseIndexTests):
112122
pass
@@ -133,6 +143,26 @@ def test_array_interface(self, data):
133143
def test_view(self, data):
134144
super().test_view(data)
135145

146+
def test_array_interface_copy(self, data):
147+
# This test was failing compliance checks due to changes in how
148+
# numpy handles processing when np.array(obj, copy=False).
149+
# Until pandas changes the existing tests, this compliance test
150+
# will continue to fail.
151+
import numpy as np
152+
from pandas.compat.numpy import np_version_gt2
153+
154+
result_copy1 = np.array(data, copy=True)
155+
result_copy2 = np.array(data, copy=True)
156+
assert not np.may_share_memory(result_copy1, result_copy2)
157+
158+
if not np_version_gt2:
159+
# copy=False semantics are only supported in NumPy>=2.
160+
return
161+
162+
result_nocopy1 = np.array(data, copy=False)
163+
result_nocopy2 = np.array(data, copy=False)
164+
assert not np.may_share_memory(result_nocopy1, result_nocopy2)
165+
136166

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

223+
def test_argmax_argmin_no_skipna_notimplemented(self, data_missing_for_sorting):
224+
# This test was failing compliance checks because it attempted to match
225+
# a pytest regex match using an empty string (""), which pytest version
226+
# 8.4.0 stopped allowing.
227+
# The test has been updated in pandas main so that it will
228+
# no longer fail, but the fix is not expected to be released until
229+
# at least pandas version 3.0 (current version is 2.3)
230+
data = data_missing_for_sorting
231+
232+
with pytest.raises(NotImplementedError):
233+
data.argmin(skipna=False)
234+
235+
with pytest.raises(NotImplementedError):
236+
data.argmax(skipna=False)
237+
193238

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

240285

241286
class TestJSONArrayReduce(base.BaseReduceTests):
242-
pass
287+
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
288+
@pytest.mark.parametrize("skipna", [True, False])
289+
def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna):
290+
op_name = all_numeric_reductions
291+
ser = pd.Series(data)
292+
293+
if not self._supports_reduction(ser, op_name):
294+
# Sum does not raise an Error (TypeError or otherwise)
295+
if op_name != "sum":
296+
with pytest.raises(TypeError):
297+
getattr(ser, op_name)(skipna=skipna)
298+
else:
299+
# min/max with empty produce numpy warnings
300+
self.check_reduce(ser, op_name, skipna)
243301

244302

245303
class TestJSONArrayReshaping(base.BaseReshapingTests):
@@ -356,6 +414,19 @@ def test_setitem_mask_boolean_array_with_na(self, data, box_in_series):
356414
def test_setitem_preserves_views(self, data):
357415
super().test_setitem_preserves_views(data)
358416

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

360431
class TestJSONArrayDim2Compat(base.Dim2CompatTests):
361432
pass

tests/compliance/time/test_time_compliance.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ class TestDtype(base.BaseDtypeTests):
5656

5757

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

6169

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

6977

7078
class TestInterface(base.BaseInterfaceTests):
71-
pass
79+
def test_array_interface_copy(self, data):
80+
# This test was failing compliance checks due to changes in how
81+
# numpy handles processing when np.array(obj, copy=False).
82+
# Until pandas changes the existing tests, this compliance test
83+
# will continue to fail.
84+
import numpy as np
85+
from pandas.compat.numpy import np_version_gt2
86+
87+
result_copy1 = np.array(data, copy=True)
88+
result_copy2 = np.array(data, copy=True)
89+
assert not np.may_share_memory(result_copy1, result_copy2)
90+
91+
if not np_version_gt2:
92+
# copy=False semantics are only supported in NumPy>=2.
93+
return
94+
95+
with pytest.raises(ValueError):
96+
result_nocopy1 = np.array(data, copy=False)
97+
result_nocopy2 = np.array(data, copy=False)
98+
assert np.may_share_memory(result_nocopy1, result_nocopy2)
7299

73100

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

96123
tm.assert_series_equal(result, expected)
97124

125+
def test_argmax_argmin_no_skipna_notimplemented(self, data_missing_for_sorting):
126+
# This test was failing compliance checks because it attempted to match
127+
# a pytest regex match using an empty string (""), which pytest version
128+
# 8.4.0 stopped allowing.
129+
# The test has been updated in pandas main so that it will
130+
# no longer fail, but the fix is not expected to be released until
131+
# at least pandas version 3.0 (current version is 2.3)
132+
data = data_missing_for_sorting
133+
134+
with pytest.raises(NotImplementedError):
135+
data.argmin(skipna=False)
136+
137+
with pytest.raises(NotImplementedError):
138+
data.argmax(skipna=False)
139+
98140

99141
class TestParsing(base.BaseParsingTests):
100142
pass
@@ -109,4 +151,15 @@ class TestReshaping(base.BaseReshapingTests):
109151

110152

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

0 commit comments

Comments
 (0)