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

repr for string item within array of dtype object is missing quotes (Trac #1361) #1959

Closed
thouis opened this issue Oct 19, 2012 · 5 comments
Closed

Comments

@thouis
Copy link
Contributor

thouis commented Oct 19, 2012

Original ticket http://projects.scipy.org/numpy/ticket/1361 on 2010-01-13 by @yarikoptic, assigned to unknown.

In numpy version shipped with Debian

$> python -c "from numpy import *; print __version__; r=repr(array(['s', None])); print r; eval(r)"
1.3.0
array([s, None], dtype=object)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 1, in <module>
NameError: name 's' is not defined

as well as current trunk

$> python -c "from numpy import *; print __version__; r=repr(array(['s', None])); print r; eval(r)"
1.5.0.dev
array([s, None], dtype=object)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 1, in <module>
NameError: name 's' is not defined
@numpy-gitbot
Copy link

@charris wrote on 2010-01-14

I suspect this is related to the fact that repr on arrays calls str on the elements rather than repr.

@numpy-gitbot
Copy link

@charris wrote on 2010-01-14

Oops, looks like repr is called on the arguments. Hmm...

@numpy-gitbot
Copy link

@yarikoptic wrote on 2012-07-23

HA -- apparently I have complained about this already ... quite some time ago and now I ran into it while reporting #641

so it would be nice if someone had a look at this ancient issue

@supermank17
Copy link

Huh, results are different if None is passed in than if another value is passed in.
For example, r=repr(array(['s', 5])); print r; eval(r) gives the expected output.

@seberg
Copy link
Member

seberg commented Feb 9, 2013

supermank17, that is because the resulting type of the array is string and not object in your example, which has different code for printing.

In any case, this behaviour is fixed starting with 1.7. so that it actually does use repr for object arrays and the examples here work. So I am closing it.

@seberg seberg closed this as completed Feb 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants