Skip to content

divide by 0 for Int64 is inconsistent with int64 #22793

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
hhuuggoo opened this issue Sep 20, 2018 · 3 comments · Fixed by #45167
Closed

divide by 0 for Int64 is inconsistent with int64 #22793

hhuuggoo opened this issue Sep 20, 2018 · 3 comments · Fixed by #45167
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@hhuuggoo
Copy link

In [5]: pd.Series([1], dtype='Int64') / pd.Series([0], dtype='Int64')                                                                                                                                                                                                           
Out[5]:                                                                                                                                                                                                                                                                         
0   NaN                                                                                                                                                                                                                                                                         
dtype: float64     

Where as

In [6]: pd.Series([1], dtype='int64') / pd.Series([0], dtype='int64')                                                                                                                                                                                                           
Out[6]:                                                                                                                                                                                                                                                                         
0    inf                                                                                                                                                                                                                                                                        
dtype: float64        

It's because of this line:

mask |= (result == np.inf) | (result == -np.inf)

Is it intentional for the new extension integer type to have different behavior here?

@WillAyd
Copy link
Member

WillAyd commented Sep 20, 2018

These should align though I think the extension type actually handles this more correctly

@WillAyd WillAyd added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff ExtensionArray Extending pandas with custom dtypes or arrays. labels Sep 20, 2018
@jorisvandenbossche
Copy link
Member

I am not sure we should change the behaviour of Series with default numpy types, as we then would deviate from numpy behaviour.

Of course for the extension Int type, we have better handling of NA compared to numpy int, so which could be a reason to actually use that here. But, since division will always result in a floating dtype (and never integer), that's not a direct benefit in this case.

We have a pd.options.mode.use_inf_as_na so people can make this in practice to behave as NA, but that is False by default.

@jbrockmendel jbrockmendel added the Numeric Operations Arithmetic, Comparison, and Logical operations label Aug 3, 2019
@mroeschke mroeschke added Bug and removed Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff labels May 13, 2020
@jbrockmendel jbrockmendel added the NA - MaskedArrays Related to pd.NA and nullable extension arrays label Dec 21, 2021
@jbrockmendel
Copy link
Member

closed by #30183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants