Skip to content

TST: Verify operators with IntegerArray and list-likes (22606) #35987

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 13 commits into from
Oct 7, 2020
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
10 changes: 10 additions & 0 deletions pandas/tests/arithmetic/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

import pandas as pd
import pandas._testing as tm

# ------------------------------------------------------------------
# Helper Functions
Expand Down Expand Up @@ -239,5 +240,14 @@ def box_with_array(request):
return request.param


@pytest.fixture(params=[pd.Index, pd.Series, tm.to_array, np.array, list], ids=id_func)
def box_1d_array(request):
"""
Fixture to test behavior for Index, Series, tm.to_array, numpy Array and list
classes
"""
return request.param


# alias so we can use the same fixture for multiple parameters in a test
box_with_array2 = box_with_array
40 changes: 39 additions & 1 deletion pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@
import pytest

import pandas as pd
from pandas import Index, Series, Timedelta, TimedeltaIndex
from pandas import Index, Int64Index, Series, Timedelta, TimedeltaIndex, array
import pandas._testing as tm
from pandas.core import ops


@pytest.fixture(params=[Index, Series, tm.to_array])
def box_pandas_1d_array(request):
"""
Fixture to test behavior for Index, Series and tm.to_array classes
"""
return request.param


def adjust_negative_zero(zero, expected):
"""
Helper to adjust the expected result if we are dividing by -0.0
Expand Down Expand Up @@ -1340,3 +1348,33 @@ def test_dataframe_div_silenced():
)
with tm.assert_produces_warning(None):
pdf1.div(pdf2, fill_value=0)


@pytest.mark.parametrize(
"data, expected_data",
[([0, 1, 2], [0, 2, 4])],
)
def test_integer_array_add_list_like(
box_pandas_1d_array, box_1d_array, data, expected_data
):
# GH22606 Verify operators with IntegerArray and list-likes
arr = array(data, dtype="Int64")
container = box_pandas_1d_array(arr)
left = container + box_1d_array(data)
right = box_1d_array(data) + container

if Series == box_pandas_1d_array:
assert_function = tm.assert_series_equal
expected = Series(expected_data, dtype="Int64")
elif Series == box_1d_array:
assert_function = tm.assert_series_equal
expected = Series(expected_data, dtype="object")
elif Index in (box_pandas_1d_array, box_1d_array):
assert_function = tm.assert_index_equal
expected = Int64Index(expected_data)
else:
assert_function = tm.assert_numpy_array_equal
expected = np.array(expected_data, dtype="object")

assert_function(left, expected)
assert_function(right, expected)