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

DataFrame division returns infinity for 0 / 0 #8445

Closed
keszybz opened this issue Oct 2, 2014 · 5 comments · Fixed by #9308
Closed

DataFrame division returns infinity for 0 / 0 #8445

keszybz opened this issue Oct 2, 2014 · 5 comments · Fixed by #9308
Labels
API Design Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@keszybz
Copy link

keszybz commented Oct 2, 2014

xref #9286

0 / 0 does not have a value, and should return NaN, not infinity.

>>> x = pd.DataFrame([[0, 0], [1, 0], [-1, 0]])
>>> x[0] / x[1]
0    inf                              <------------- here
1    inf
2   -inf
dtype: float64

numpy does this correctly:

>>> y = np.array([[0, 0], [1, 0], [-1, 0]])
>>> y[:, 0] / y[:, 1]
array([ nan,  inf, -inf])
@jreback
Copy link
Contributor

jreback commented Oct 2, 2014

show your numpy/pandas versions.

numpy used to get this completely wrong for integer division (it would return 0,0,0) in 1.8.1

not sure if they fixed it in 1.9

@keszybz
Copy link
Author

keszybz commented Oct 2, 2014

>>> pd.__version__
'0.14.1'
>>> np.__version__
'1.9.0'
>>> sys.version
'2.7.5 (default, Jun 25 2014, 10:19:55) \n[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)]'

@jreback
Copy link
Contributor

jreback commented Oct 2, 2014

I think I can buy adding this

want to add a test here: https://github.com/pydata/pandas/blob/master/pandas/tests/test_series.py#L2491
(prob need to restrict this testing to >= 1.9) and test separately for < 1.9

and fix (which is a teeny bit more complicated) (see core/common/fill_zeros)

cc @seth-p

agree?

@jreback jreback added API Design Numeric Operations Arithmetic, Comparison, and Logical operations Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Oct 2, 2014
@jreback jreback added this to the 0.15.1 milestone Oct 2, 2014
@seth-p
Copy link
Contributor

seth-p commented Oct 2, 2014

I agree that 0/0 should be NaN, not inf.

@jreback
Copy link
Contributor

jreback commented Oct 3, 2014

cc @jaimefrio
(sorry mispelled before). I think 1.10 in numpy is now in sync AFAIK (< 1.10 not so much though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants