Skip to content
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

TST: Add ExtensionArray base tests for ops between pandas objects and EAs #22974

Open
TomAugspurger opened this issue Oct 3, 2018 · 6 comments
Labels
Docs ExtensionArray Extending pandas with custom dtypes or arrays. Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Oct 3, 2018

We should document the expected behavior for binary operations between ExtensionArrays and pandas' own objects (Series, DataFrame, Index). We should update our own EAs to match the docs.

In [4]: integer_array([1, 2]) + pd.Series([1, 2])
Out[4]: IntegerArray([2, 4], dtype='Int64')

Out[4] should be a Series with "Int64" dtype, to match the behavior of ndarray + series.

We've documented this, but need to test between series, index, dataframe, and the array class

def test_arith_series_with_array(self, data, all_arithmetic_operators):
# ndarray & other series
op_name = all_arithmetic_operators
s = pd.Series(data)
self.check_opname(s, op_name, pd.Series([s.iloc[0]] * len(s)),
exc=self.series_array_exc)

@TomAugspurger TomAugspurger added Docs Numeric Operations Arithmetic, Comparison, and Logical operations ExtensionArray Extending pandas with custom dtypes or arrays. labels Oct 3, 2018
@TomAugspurger TomAugspurger added this to the 0.24.0 milestone Oct 3, 2018
@jorisvandenbossche
Copy link
Member

and also the interaction with non-pandas objects (lists, arrays)

@TomAugspurger
Copy link
Contributor Author

Tangentially related, I noticed today that divmod(ndarray, Series) raises.

In [3]: arr = np.array([1, 2])

In [4]: divmod(arr, pd.Series(arr))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-b14c14fd32f3> in <module>
----> 1 divmod(arr, pd.Series(arr))

TypeError: unsupported operand type(s) for divmod(): 'numpy.ndarray' and 'Series'

Given that both division on mod work, divmod probably should as well.

@jbrockmendel
Copy link
Member

Tangentially related, I noticed today that divmod(ndarray, Series) raises.

I think this is #19252.

@TomAugspurger
Copy link
Contributor Author

I think this is sufficiently documented in extending.rst. Closing.

@jorisvandenbossche
Copy link
Member

It's indeed written in the docs, but do we actually properly test it in the base tests?

Because eg test_arith_series_with_array

def test_arith_series_with_array(self, data, all_arithmetic_operators):
# ndarray & other series
op_name = all_arithmetic_operators
s = pd.Series(data)
self.check_opname(s, op_name, pd.Series([s.iloc[0]] * len(s)),
exc=self.series_array_exc)

is actually testing the op with series and series, not series and array.

And we also don't have it with eg Index or DataFrame.

@TomAugspurger
Copy link
Contributor Author

Ok, will re-purpose for tests.

@TomAugspurger TomAugspurger reopened this Nov 6, 2018
@TomAugspurger TomAugspurger changed the title Document, implement EA and Series binops TST: Add ExtensionArray base tests for ops between pandas objects and EAs Nov 6, 2018
@jreback jreback modified the milestones: 0.24.0, Contributions Welcome Dec 2, 2018
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs ExtensionArray Extending pandas with custom dtypes or arrays. Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

No branches or pull requests

5 participants