Skip to content

PERF: Fixed decoding perf issue on py3 (GH5441) #5448

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

Merged
merged 1 commit into from
Nov 6, 2013
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ Bug Fixes
names weren't strings (:issue:`4956`)
- A zero length series written in Fixed format not deserializing properly.
(:issue:`4708`)
- Fixed decoding perf issue on pyt3 (:issue:`5441`)
- Fixed bug in tslib.tz_convert(vals, tz1, tz2): it could raise IndexError
exception while trying to access trans[pos + 1] (:issue:`4496`)
- The ``by`` argument now works correctly with the ``layout`` argument
Expand Down
7 changes: 5 additions & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3972,8 +3972,11 @@ def _unconvert_string_array(data, nan_rep=None, encoding=None):
# where the passed encoding is actually None)
encoding = _ensure_encoding(encoding)
if encoding is not None and len(data):
f = np.vectorize(lambda x: x.decode(encoding), otypes=[np.object])
data = f(data)
try:
data = data.astype(str).astype(object)
Copy link
Contributor

Choose a reason for hiding this comment

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

So this branch works when you only have ascii letters/numbers in your output? Otherwise always needs to be decoded, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no it always works with an individual decoding, just slow. the astyping to str works when the input can be safely decoded by the astype(str) (which is prob just a UTF-8 decode on numpy side thats in c)

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay (I meant the astyping line) sounds good.

except:
f = np.vectorize(lambda x: x.decode(encoding), otypes=[np.object])
data = f(data)

if nan_rep is None:
nan_rep = 'nan'
Expand Down