Skip to content

BUG: Fix move_into_mutable_buffer for python 3.6. #14695

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
wants to merge 1 commit into from

Conversation

llllllllll
Copy link
Contributor

In python 3.6, the CALL_FUNCTION handling was updated. One change is
that when calling a C function from a python function python now counts
the reference owned by the argument tuple. This means that move was
always seeing objects with two references instead of the expected
one.

Python 3.6 also removed a copy in the argument tuple when *unpacking
functions. This means that if a user does:

tuple = (create_string(),)
move_into_mutable_buffer(*tuple)

where create_string() creates a string object with one reference then we
will fail to raise a BadMove even though the user could later retrieve
that string with tuple[0]. There is no way to detect this case so this
patch adds a warning to the docstring advising against star unpacking.

xref: #14679

I played around with removing the extra reference that was added in 3.6 but it looks like playing with borrowed refs everywhere will be a bit tricky. This change should clear things up for 3.6 while continuing to work for older versions. In 3.6 you could get a shared mutable string from this but you need to try pretty hard for it.

@jreback jreback added the Compat pandas objects compatability with Numpy or Python functions label Nov 21, 2016
@codecov-io
Copy link

codecov-io commented Nov 21, 2016

Current coverage is 85.20% (diff: 100%)

Merging #14695 into master will increase coverage by <.01%

@@             master     #14695   diff @@
==========================================
  Files           143        143          
  Lines         50787      50787          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43273      43274     +1   
+ Misses         7514       7513     -1   
  Partials          0          0          

Powered by Codecov. Last update f26b049...d1e8b1b

In python 3.6, the CALL_FUNCTION handling was updated. One change is
that when calling a C function from a python function python now counts
the reference owned by the argument tuple. This means that move was
always seeing objects with two references instead of the expected
one.

Python 3.6 also removed a copy in the argument tuple when *unpacking
functions. This means that if a user does:

tuple = (create_string(),)
move_into_mutable_buffer(*tuple)

where create_string() creates a string object with one reference then we
will fail to raise a BadMove even though the user could later retrieve
that string with tuple[0]. There is no way to detect this case so this
patch adds a warning to the docstring advising against star unpacking.
@llllllllll
Copy link
Contributor Author

ping: tests passing now.

@jreback jreback added this to the 0.19.2 milestone Nov 22, 2016
@jreback
Copy link
Contributor

jreback commented Nov 22, 2016

thanks @llllllllll

@jreback jreback closed this in f609640 Nov 22, 2016
jorisvandenbossche pushed a commit to jorisvandenbossche/pandas that referenced this pull request Dec 14, 2016
…hon 3.6.

In python 3.6, the CALL_FUNCTION handling was updated. One change is
that when calling a C function from a python function python now
counts  the reference owned by the argument tuple. This means that
move was  always seeing objects with two references instead of the
expected  one.    Python 3.6 also removed a copy in the argument tuple
when *unpacking  functions. This means that if a user does:    tuple =
(create_string(),)  move_into_mutable_buffer(*tuple)    where
create_string() creates a string object with one reference then we
will fail to raise a BadMove even though the user could later retrieve
that string with tuple[0]. There is no way to detect this case so this
patch adds a warning to the docstring advising against star unpacking.
xref: pandas-dev#14679    I played around with removing the extra reference that
was added in 3.6 but it looks like playing with borrowed refs
everywhere will be a bit tricky. This change should clear things up
for 3.6 while continuing to work for older versions. In 3.6 you
__could__ get a shared mutable string from this but you need to try
pretty hard for it.

Author: Joe Jevnik <[email protected]>

Closes pandas-dev#14695 from llllllllll/move-3.6-compat and squashes the following commits:

d1e8b1b [Joe Jevnik] BUG: Fix move_into_mutable_buffer for python 3.6.

(cherry picked from commit f609640)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants