Skip to content

Fix unicode repr object #459

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 3 commits into from
Oct 3, 2012
Merged

Conversation

jseabold
Copy link
Contributor

If you try to print an array with unicode in it and an object dtype, it currently fails. This happens often for me working with pandas because it defaults to the object dtype for non-numerical arrays. This is because the fallback for the formatting is str. Is there any reason not to use the numpystr function here that can handle unicode?

Reproduce

import numpy as np
a = np.array([u"\xe9"], dtype=object)
print a

@njsmith
Copy link
Member

njsmith commented Sep 26, 2012

You have test failures on Py3 (see travis logs).

@jseabold
Copy link
Contributor Author

Should be okay now.

def test_unicode_object_array():
import sys
if sys.version_info[0] >= 3:
expected = "array(['é'], dtype=object)"
Copy link
Member

Choose a reason for hiding this comment

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

Not sure whether we care, but if it's desireable to keep the source files as ascii, I think this line could be written

expected = u"array(['\xe9'], dtype=object)"

and work on both py2 and py3.

Copy link
Member

Choose a reason for hiding this comment

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

Err, that's if we're running stuff through 2to3. If not then we can leave off the u at the beginning and I believe it should still work (though be slightly more confusing).

@jseabold
Copy link
Contributor Author

jseabold commented Oct 3, 2012

Any reason not to merge this? Lost track of the release schedule, but it'd be great to get this in if possible.

@njsmith
Copy link
Member

njsmith commented Oct 3, 2012

I thought maybe others would comment on the bit about including raw unicode characters in source files, but apparently not, and the tests pass, so hey.

njsmith added a commit that referenced this pull request Oct 3, 2012
@njsmith njsmith merged commit 43f1d5c into numpy:master Oct 3, 2012
@certik certik mentioned this pull request Dec 16, 2012
@certik
Copy link
Contributor

certik commented Dec 16, 2012

Backported in #2842.

BvB93 pushed a commit to BvB93/numpy that referenced this pull request Dec 19, 2020
It's been non-functional for the past 8 years (xref numpy#459)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants