Skip to content

Commit 50c4fbc

Browse files
TST: Verify operators with IntegerArray and list-likes (22606) (#35987)
1 parent 3402233 commit 50c4fbc

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

pandas/tests/arithmetic/conftest.py

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
import pandas as pd
5+
import pandas._testing as tm
56

67
# ------------------------------------------------------------------
78
# Helper Functions
@@ -230,5 +231,14 @@ def box_with_array(request):
230231
return request.param
231232

232233

234+
@pytest.fixture(params=[pd.Index, pd.Series, tm.to_array, np.array, list], ids=id_func)
235+
def box_1d_array(request):
236+
"""
237+
Fixture to test behavior for Index, Series, tm.to_array, numpy Array and list
238+
classes
239+
"""
240+
return request.param
241+
242+
233243
# alias so we can use the same fixture for multiple parameters in a test
234244
box_with_array2 = box_with_array

pandas/tests/arithmetic/test_numeric.py

+39-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@
1111
import pytest
1212

1313
import pandas as pd
14-
from pandas import Index, Series, Timedelta, TimedeltaIndex
14+
from pandas import Index, Int64Index, Series, Timedelta, TimedeltaIndex, array
1515
import pandas._testing as tm
1616
from pandas.core import ops
1717

1818

19+
@pytest.fixture(params=[Index, Series, tm.to_array])
20+
def box_pandas_1d_array(request):
21+
"""
22+
Fixture to test behavior for Index, Series and tm.to_array classes
23+
"""
24+
return request.param
25+
26+
1927
def adjust_negative_zero(zero, expected):
2028
"""
2129
Helper to adjust the expected result if we are dividing by -0.0
@@ -1330,3 +1338,33 @@ def test_dataframe_div_silenced():
13301338
)
13311339
with tm.assert_produces_warning(None):
13321340
pdf1.div(pdf2, fill_value=0)
1341+
1342+
1343+
@pytest.mark.parametrize(
1344+
"data, expected_data",
1345+
[([0, 1, 2], [0, 2, 4])],
1346+
)
1347+
def test_integer_array_add_list_like(
1348+
box_pandas_1d_array, box_1d_array, data, expected_data
1349+
):
1350+
# GH22606 Verify operators with IntegerArray and list-likes
1351+
arr = array(data, dtype="Int64")
1352+
container = box_pandas_1d_array(arr)
1353+
left = container + box_1d_array(data)
1354+
right = box_1d_array(data) + container
1355+
1356+
if Series == box_pandas_1d_array:
1357+
assert_function = tm.assert_series_equal
1358+
expected = Series(expected_data, dtype="Int64")
1359+
elif Series == box_1d_array:
1360+
assert_function = tm.assert_series_equal
1361+
expected = Series(expected_data, dtype="object")
1362+
elif Index in (box_pandas_1d_array, box_1d_array):
1363+
assert_function = tm.assert_index_equal
1364+
expected = Int64Index(expected_data)
1365+
else:
1366+
assert_function = tm.assert_numpy_array_equal
1367+
expected = np.array(expected_data, dtype="object")
1368+
1369+
assert_function(left, expected)
1370+
assert_function(right, expected)

0 commit comments

Comments
 (0)