-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: always make ndarrays from msgpack writable #12359
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
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9cd9d80
ENH: always make ndarrays from msgpack writable
830abba
TST: adds test for memoized empty string and chars
330dd76
ENH: updates unconvert no-copy code to be safer
84d7275
ENH: reimplement `_move_into_mutable_buffer` in C.
e896603
TST: adds `pandas.util.testing.patch`
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
import nose | ||
|
||
from pandas.util._move import move_into_mutable_buffer, BadMove | ||
from pandas.util.decorators import deprecate_kwarg | ||
from pandas.util.validators import validate_args, validate_kwargs | ||
|
||
|
@@ -150,6 +151,38 @@ def test_validation(self): | |
kwargs = {'f': 'foo', 'b': 'bar'} | ||
validate_kwargs('func', kwargs, *compat_args) | ||
|
||
|
||
class TestMove(tm.TestCase): | ||
def test_more_than_one_ref(self): | ||
"""Test case for when we try to use ``move_into_mutable_buffer`` when | ||
the object being moved has other references. | ||
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. its funny, when you use a doc-string it calls the test by this. I guess that is right. 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. Should I just make this a comment instead or do you not mind? |
||
""" | ||
b = b'testing' | ||
|
||
with tm.assertRaises(BadMove) as e: | ||
def handle_success(type_, value, tb): | ||
self.assertIs(value.args[0], b) | ||
return type(e).handle_success(e, type_, value, tb) # super | ||
|
||
e.handle_success = handle_success | ||
move_into_mutable_buffer(b) | ||
|
||
def test_exactly_one_ref(self): | ||
"""Test case for when the object being moved has exactly one reference. | ||
""" | ||
b = b'testing' | ||
|
||
# We need to pass an expression on the stack to ensure that there are | ||
# not extra references hanging around. We cannot rewrite this test as | ||
# buf = b[:-3] | ||
# as_stolen_buf = move_into_mutable_buffer(buf) | ||
# because then we would have more than one reference to buf. | ||
as_stolen_buf = move_into_mutable_buffer(b[:-3]) | ||
|
||
# materialize as bytearray to show that it is mutable | ||
self.assertEqual(bytearray(as_stolen_buf), b'test') | ||
|
||
|
||
if __name__ == '__main__': | ||
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], | ||
exit=False) |
Oops, something went wrong.
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.
I would try to import these at the top of the file and just set variables (
_ZLIB_INSTALLED
,_BLOSC_INSTALLED
); and you can do whatever imports you need there.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.
done, added
_check_*
functions to raise a valueerror here if you try to use a compressor that is not installed