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

Maximum recursion level reached in Python 3 #221

Closed
horejsek opened this issue May 21, 2016 · 6 comments
Closed

Maximum recursion level reached in Python 3 #221

horejsek opened this issue May 21, 2016 · 6 comments

Comments

@horejsek
Copy link

ujson fails with maximum level reached for numpy array of ints in Python 3. It's probably not problem of ujson, but anyway I think ujson should end with better message. Something like „xy is not serializable because it fails with“ so developer know what to look for.

➜  ~ python2
Python 2.7.9 
>>> import ujson
>>> import numpy
>>> ujson.dumps(numpy.array([1.0, 2.0, 3.0]))
'[1.0,2.0,3.0]'
>>> ujson.dumps(numpy.array([1, 2, 3]))
'[1,2,3]'

➜  ~ python3
Python 3.5.0
>>> import ujson
>>> import numpy
>>> ujson.dumps(numpy.array([1.0, 2.0, 3.0]))
'[1.0,2.0,3.0]'
>>> ujson.dumps(numpy.array([1, 2, 3]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Maximum recursion level reached
@rafaelreuber
Copy link

I'm facing a similar problem

@mthh
Copy link

mthh commented Jun 30, 2016

EDIT: My bad, it wasn't fixing anything (I just ran my test only on a numpy array of float which doesn't seems to be a problem (python 2 or 3) as it only occurs with arrays of integers on python 3);

I also saw this issue is related to #204 and #164. I guess it could be due to numpy.int64 which isn't instance of int in python 3 (while it is in python 2, and while numpy.float64 are instance of float in both cases).

It might be fixed by using the Number Protocol of the python API when checking value type but some people more familiar with python c api might need to confirm.

@horejsek
Copy link
Author

horejsek commented Jul 1, 2016

Good work!

@tlbtlbtlb
Copy link

Also in python 2, arrays of numpy.float32 fail while float64 is fine:

>>> import numpy, ujson
>>> x64=numpy.array([1.0, 2.0])
>>> x32=numpy.array([1.0, 2.0], dtype=numpy.float32)
>>> ujson.dumps(x64)
'[1.0,2.0]'
>>> ujson.dumps(x32)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Maximum recursion level reached

@Jahaja
Copy link
Contributor

Jahaja commented Feb 6, 2017

Resolved in 53f85b1 by no longer trying to serialize these.

@ringsaturn
Copy link

NumPy int64 has been fixed with caiyunapp/ultrajson with calling NumPy's header in C.

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 a pull request may close this issue.

6 participants