-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: 0/frame numeric ops buggy (GH9144) #9308
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
) | ||
from pandas import compat | ||
|
||
from numpy import random, nan | ||
from numpy import random, nan, inf | ||
from numpy.random import randn | ||
import numpy as np | ||
import numpy.ma as ma | ||
|
@@ -5138,23 +5138,26 @@ def test_modulo(self): | |
|
||
def test_div(self): | ||
|
||
# integer div, but deal with the 0's | ||
# integer div, but deal with the 0's (GH 9144) | ||
p = DataFrame({ 'first' : [3,4,5,8], 'second' : [0,0,0,3] }) | ||
result = p / p | ||
|
||
### this is technically wrong as the integer portion is coerced to float ### | ||
expected = DataFrame({ 'first' : Series([1,1,1,1],dtype='float64'), 'second' : Series([np.inf,np.inf,np.inf,1]) }) | ||
expected = DataFrame({'first': Series([1.0, 1.0, 1.0, 1.0]), | ||
'second': Series([nan, nan, nan, 1])}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the issue number here as a comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks. |
||
assert_frame_equal(result,expected) | ||
|
||
result2 = DataFrame(p.values.astype('float64')/p.values,index=p.index,columns=p.columns).fillna(np.inf) | ||
result2 = DataFrame(p.values.astype('float') / p.values, index=p.index, | ||
columns=p.columns) | ||
assert_frame_equal(result2,expected) | ||
|
||
result = p / 0 | ||
expected = DataFrame(np.inf,index=p.index,columns=p.columns) | ||
expected = DataFrame(inf, index=p.index, columns=p.columns) | ||
expected.iloc[0:3, 1] = nan | ||
assert_frame_equal(result,expected) | ||
|
||
# numpy has a slightly different (wrong) treatement | ||
result2 = DataFrame(p.values.astype('float64')/0,index=p.index,columns=p.columns).fillna(np.inf) | ||
result2 = DataFrame(p.values.astype('float64') / 0, index=p.index, | ||
columns=p.columns) | ||
assert_frame_equal(result2,expected) | ||
|
||
p = DataFrame(np.random.randn(10, 5)) | ||
|
@@ -5604,7 +5607,7 @@ def test_arith_flex_series(self): | |
|
||
# broadcasting issue in GH7325 | ||
df = DataFrame(np.arange(3*2).reshape((3,2)),dtype='int64') | ||
expected = DataFrame([[np.inf,np.inf],[1.0,1.5],[1.0,1.25]]) | ||
expected = DataFrame([[nan, inf], [1.0, 1.5], [1.0, 1.25]]) | ||
result = df.div(df[0],axis='index') | ||
assert_frame_equal(result,expected) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on #19322 it looks like the problem would be solved by making this condition include other "div" operations. Was there a specific reason to only include floordiv here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid I don't remember why only floordiv is here, but I do tend to comment non-obvious, intentional choices, so I'm guessing it was not intended that only floordiv be here.