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

BUG: wrap __idiv__ to avoid making a copy (#12962) #17589

Merged
merged 1 commit into from
Sep 25, 2017

Conversation

dkamm
Copy link
Contributor

@dkamm dkamm commented Sep 19, 2017

  • closes __idiv__ creates a copy? #12962
  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatnew- just calls _wrap_inplace_method and extends test_inplace_ops_identity

@codecov
Copy link

codecov bot commented Sep 19, 2017

Codecov Report

Merging #17589 into master will decrease coverage by 0.01%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17589      +/-   ##
==========================================
- Coverage   91.26%   91.24%   -0.02%     
==========================================
  Files         163      163              
  Lines       49806    49808       +2     
==========================================
- Hits        45455    45448       -7     
- Misses       4351     4360       +9
Flag Coverage Δ
#multiple 89.04% <66.66%> (ø) ⬆️
#single 40.31% <66.66%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/ops.py 91.88% <66.66%> (+0.02%) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.73% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6da85b3...4a92688. Read the comment docs.

@gfyoung gfyoung added Bug Dtype Conversions Unexpected or buggy dtype conversions Numeric Operations Arithmetic, Comparison, and Logical operations labels Sep 19, 2017
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add a whatnew note -

assert id(df) == expected
df *= 2.
assert id(df) == expected
df /= 2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fails before your change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it will only fail for python 2.7 using classic division (which people shouldn't be using but the behavior is still unexpected)

you can verify by doing
git checkout master pandas/core/ops.py ; pytest pandas/tests/frame/test_operators.py
since the fix and test are in one commit.

assert id(df) == expected
df /= 2.
assert id(df) == expected
df **= 2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add for // as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more missing inplace operators (ifloordiv, imod, iand, ior, ixor). The only ones excluded now are iconcat, ilshift and irshift which I believe are not supported.

@@ -186,8 +186,10 @@ def add_special_arithmetic_methods(cls, arith_method=None,
arith_method : function (optional)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not make sense for arith_method to be an optional argument because _create_methods will try to call it without checking if it is None

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok this looks good. suggestions on more comprehensive testing, pls add a whatsnew note as well. ping on green.

# no id change
df = DataFrame({'a': [1., 2., 3.]})
expected = id(df)
df += 2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this a new test, ideally you can parametrize this and also test (in addition to identity) equality with the non-inplace op
e.g. something like

@pytest.mark.parmatrize('op', ['add', 'sub'......])
def test_inplace_ops_identity2(self, op):
       df = DataFrame(...)
       df_copy = df.copy()
       iop = '__i{}__'.format(op)
       op = '__{}__'.format(op)
       
       getattr(df, iop)(2.)
       expected = getattr(df_copy, op)(2.)
       tm.assert_frame_equal(df, expected)
       ....check id here too

@pep8speaks
Copy link

pep8speaks commented Sep 24, 2017

Hello @dkamm! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on September 24, 2017 at 22:10 Hours UTC

@jreback jreback merged commit 9d0db60 into pandas-dev:master Sep 25, 2017
@jreback
Copy link
Contributor

jreback commented Sep 25, 2017

thanks!

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 Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

__idiv__ creates a copy?
4 participants