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 7 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
9 changes: 9 additions & 0 deletions pandas/tests/arithmetic/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,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
25 changes: 24 additions & 1 deletion pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytest

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

Expand Down Expand Up @@ -1297,3 +1297,26 @@ def test_dataframe_div_silenced():
)
with tm.assert_produces_warning(None):
pdf1.div(pdf2, fill_value=0)


@pytest.fixture(params=[Index, Series, tm.to_array])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would put this near the top

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

def box_pandas_1d_array(request):
"""
Fixture to test behavior for Index, Series and tm.to_array classes
"""
return request.param


@pytest.mark.parametrize(
"data, expected", [([0, 1, 2], [0, 2, 4])],
)
def test_integer_array_add_list_like(box_pandas_1d_array, box_1d_array, data, expected):
# 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

assert left.tolist() == expected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this also check that the interior elements are the same e.g. that they are python ints and NOT np.int64 for example? cc @jbrockmendel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not check if interior elements are the same. Think this can be solved by performing comparison on np.array.

Converted output to np.array instead of list and now use tm.assert_numpy_array_equal with check_dtype=True

assert right.tolist() == expected