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 3 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, pandas 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
13 changes: 13 additions & 0 deletions pandas/tests/arithmetic/test_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import pytest

from pandas import Series
import pandas._testing as tm
from pandas.core.ops.array_ops import comparison_op, na_logical_op

Expand Down Expand Up @@ -34,3 +35,15 @@ def test_object_comparison_2d():
right.flags.writeable = False
result = comparison_op(left, right, operator.ne)
tm.assert_numpy_array_equal(result, ~expected)


@pytest.mark.parametrize(
"data, expected", [([0, 1, 2], [0, 2, 4])],
)
def test_extension_array_add(box_1d_array, data, expected):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you parameterize ser on Series, to_array, Index (you can just make another box parameter but doesn't need to go in conftest it can be here)

Copy link
Contributor Author

@avinashpancham avinashpancham Sep 6, 2020

Choose a reason for hiding this comment

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

Based on master it seems that Index and to_array do not yet support initialization from an ExtensionArray. Series dtype is correctly set to Int64, but Index and to_array have an object dtype and not an integer dtype. Do we then still want to add parametrize ser?

>>> import pandas as pd 
>>> import pandas._testing as tm

>>>  arr = pd.array([0, 1, 2 ], pd.Int64Dtype())

>>> pd.Series(arr)
0    0
1    1
2    2
dtype: Int64

>>> pd.Index(arr)
Index([0, 1, 2], dtype='object')

>>> tm.to_array(arr)
array([0, 1, 2], dtype=object)

Copy link
Contributor

Choose a reason for hiding this comment

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

Index is correct. the to_array actually need to be fixed to simply call pd.array (try this and see if it just works, if it does ok), if now we can do after.

Copy link
Contributor Author

@avinashpancham avinashpancham Sep 13, 2020

Choose a reason for hiding this comment

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

Add parametrization to test Series, Index and tm.to_array.

Didnt update the to_array function to simply call pd.array, since multiple tests in the test suite failed when I did that. Can open a PR to explore that next week.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback could you have a 2nd look? Thanks!

# GH22606 Verify operators with Extension Array and list-likes
ser = Series(data, dtype="Int64")
results = ser + box_1d_array(data)

expected = Series(expected, dtype="Int64")
tm.assert_series_equal(results, expected)