Skip to content

Wired behavior: 0 / dataframe = inf while 0.0 / dataframe = 0.0 #9144

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
skinnymonkey opened this issue Dec 24, 2014 · 2 comments · Fixed by #9308
Closed

Wired behavior: 0 / dataframe = inf while 0.0 / dataframe = 0.0 #9144

skinnymonkey opened this issue Dec 24, 2014 · 2 comments · Fixed by #9308
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@skinnymonkey
Copy link

In [3]: s = pd.Series([1.0, 2.0])

In [4]: 0 / s
Out[4]:
0    inf
1    inf
dtype: float64

In [5]: 0.0 / s
Out[5]:
0    0
1    0
dtype: float64

This is seems quite wired. Should not 0/s be 0 as well?

@jreback
Copy link
Contributor

jreback commented Dec 24, 2014

that is a bug. Their is a whole set of logic to properly handle division by 0 property (as numpy doesn't handle integer division correctly). And fill appropriately with +-inf/NaN as appropriate.

These both should yield the same as [5]

This op is handled as __rdiv__ IOW, a reversed division op. And I think the logic is a bit off for this case.

Welcome to have you dive in if you'd like.

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions labels Dec 24, 2014
@jreback jreback added this to the 0.16.0 milestone Dec 24, 2014
@Garrett-R
Copy link
Contributor

Good catch @skinnymonkey! I think there's actually two problems related problems. The other was that:

Series([0, 1]) / 0

turned out to evaluate to Series([np.inf, np.inf]) instead of Series([np.nan, np.inf]).

Garrett-R added a commit to Garrett-R/pandas that referenced this issue Feb 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants