Skip to content

divide by 0 for Int64 is inconsistent with int64 #22793

@hhuuggoo

Description

@hhuuggoo
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?

Activity

WillAyd

WillAyd commented on Sep 20, 2018

@WillAyd
Member

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

added
AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff
ExtensionArrayExtending pandas with custom dtypes or arrays.
on Sep 20, 2018
jorisvandenbossche

jorisvandenbossche commented on Sep 21, 2018

@jorisvandenbossche
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.

added and removed
AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff
on May 13, 2020
jbrockmendel

jbrockmendel commented on Jan 2, 2022

@jbrockmendel
Member

closed by #30183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExtensionArrayExtending pandas with custom dtypes or arrays.NA - MaskedArraysRelated to pd.NA and nullable extension arraysNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @hhuuggoo@WillAyd@jorisvandenbossche@jbrockmendel@mroeschke

      Issue actions

        divide by 0 for Int64 is inconsistent with int64 · Issue #22793 · pandas-dev/pandas