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

COMPAT: Update for NumPy dev #17987

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,11 @@ def unconvert(values, dtype, compress=None):
)
# fall through to copying `np.fromstring`

# Copy the string into a numpy array.
return np.fromstring(values, dtype=dtype)
# Copy the bytes into a numpy array.
buf = np.frombuffer(values, dtype=dtype)
buf = buf.copy() # required to not mutate the original data
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's safe to not copy here, IIRC values is pile of bytes read from a msgpack file, so no risk in mutating?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the copy the test failed:

        for buf, control_buf in zip(not_garbage, control):
            # make sure none of our mutations above affected the
            # original buffers
>           assert buf == control_buf
E           AssertionError: assert b'\x00\x00\x0...x00\x00@\x8f@' == bytearray(b'\x...00\x008\x8f@')
E             At index 6 diff: 240 != 0
E             Use -v to get the full diff

pandas/tests/io/test_packers.py:690: AssertionError

I didn't look closely to see if that's a legitimate problem or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, in that case I would trust the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

you need to do this conditionally for numpy > 1.13 I think

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests on the older NumPy passed, let me make sure zlib is installed and that they weren't skipped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty sure that https://travis-ci.org/pandas-dev/pandas/jobs/292845756 hit it, so I think we're OK.

buf.flags.writeable = True
return buf


def encode(obj):
Expand Down