-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Conversation
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) |
There was a problem hiding this comment.
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')
)
There was a problem hiding this comment.
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.
@pytest.mark.parametrize( | ||
"data, expected", [([0, 1, 2], [0, 2, 4])], | ||
) | ||
def test_extension_array_add(box_1d_array, data, expected): |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
@@ -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]) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@jreback could you have another look? Thanks! |
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. |
@jreback merged master and everything passes. I did see that the fixtures are now updated to use |
thanks @avinashpancham |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff