Skip to content

Handling underlying exceptions in ExtensionArrayOpsMixin #22944

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

Closed
TomAugspurger opened this issue Oct 2, 2018 · 3 comments
Closed

Handling underlying exceptions in ExtensionArrayOpsMixin #22944

TomAugspurger opened this issue Oct 2, 2018 · 3 comments
Labels
Dtype Conversions Unexpected or buggy dtype conversions ExtensionArray Extending pandas with custom dtypes or arrays. Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@TomAugspurger
Copy link
Contributor

I'm growing to dislike the try / except to wrap the results of a binop. That's what hid #22930.

I wonder, is it possible for EA authors to annotate which ops form an algebra for their Extension type, so that we can know ahead of time whether the result should be wrappe? Something like

_ops_return_ea = {
    '__add__', '__sub__', ...
}

and if the op name is in those, then we attempt to wrap the result, but don't catch any errors? If the op name isn't in those then we return an ndarray?

The thing that would ruin this is if there were legitimate cases where whether or not the result can be wrapped depends on the value, rather than the type. Can we think of any of those?

cc @Dr-Irv

@TomAugspurger TomAugspurger added Dtype Conversions Unexpected or buggy dtype conversions Numeric Operations Arithmetic, Comparison, and Logical operations ExtensionArray Extending pandas with custom dtypes or arrays. labels Oct 2, 2018
@TomAugspurger TomAugspurger changed the title ExtensionArrayOpsMixin Handling underlying exceptions in ExtensionArrayOpsMixin Oct 2, 2018
@jorisvandenbossche
Copy link
Member

It is only done like that for the ScalarOpsMixin, correct?
So I understand your point, it's certainly brittle, but it is also maybe not that worth adding too much complexity for it. If you want to be sure what is returned, you can always add the operations yourself.

@TomAugspurger
Copy link
Contributor Author

Right, this is just for ScalarOpsMixin. Let's ignore it for now.

@TomAugspurger TomAugspurger added this to the No action milestone Oct 2, 2018
@Dr-Irv
Copy link
Contributor

Dr-Irv commented Oct 3, 2018

Just to add to the discussion @TomAugspurger, I did it this way because I have ops that take two EA's of the same type and produce an EA of a different type. In some sense, divmod is like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions ExtensionArray Extending pandas with custom dtypes or arrays. Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

No branches or pull requests

3 participants