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

Conversation

avinashpancham
Copy link
Contributor

@avinashpancham
Copy link
Contributor Author

Do we also want tests for other operators ( -, /, * ,etc)?

)
def test_extension_array_add(box_extension_array, data, expected):
# GH22606 Verify operators with Extension Array and list-likes
ser = Series(data)
Copy link
Member

@MarcoGorelli MarcoGorelli Aug 31, 2020

Choose a reason for hiding this comment

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

Hi @avinashpancham ,

from what I've understood of #22606, this should hold an ExtensionArray (e.g. it could hold nullable integers, like Series([1, 2, 3], dtype='Int64'))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see. Updated it to test for a Series that holds an ExtensionArray.

@jreback jreback added ExtensionArray Extending pandas with custom dtypes or arrays. Testing pandas testing functions or related to the test suite labels Sep 1, 2020
@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!

@avinashpancham avinashpancham changed the title TST: Verify operators with Extension Array and list-likes (22606) TST: Verify operators with IntegerArray and list-likes (22606) Sep 14, 2020
@@ -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

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

# GH22606 Verify operators with IntegerArray and list-likes
arr = array(data, dtype="Int64")
container = box_pandas_1d_array(arr)
left = np.array(container + box_1d_array(data))
Copy link
Contributor

Choose a reason for hiding this comment

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

don't wrap left / right in np.array; this makes this way more confusing. These types so should preserve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated it such that we assert using the original types.

@avinashpancham
Copy link
Contributor Author

@jreback could you have another look? Thanks!

@jreback jreback added this to the 1.2 milestone Oct 2, 2020
@jreback
Copy link
Contributor

jreback commented Oct 2, 2020

I think we just merged a change by @jbrockmendel that updated this fixture (the box_1d), so pls merge master again and ping on green.

@avinashpancham
Copy link
Contributor Author

@jreback merged master and everything passes. I did see that the fixtures are now updated to use pd.array instead of tm.to_array. Do we want to update this PR to reflect this new approach?

@jreback jreback merged commit 50c4fbc into pandas-dev:master Oct 7, 2020
@jreback
Copy link
Contributor

jreback commented Oct 7, 2020

thanks @avinashpancham

kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TST: test that operations with Series(ExtensionArray) and list-likes work
4 participants