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

newint changes behavior of int on numpy.string_ conversion #196

Open
ssolari opened this issue Feb 17, 2016 · 3 comments
Open

newint changes behavior of int on numpy.string_ conversion #196

ssolari opened this issue Feb 17, 2016 · 3 comments

Comments

@ssolari
Copy link

ssolari commented Feb 17, 2016

newint blows up code that works with 'int' in python 2 on numpy strings. python 3 int works as expected. When both python 2 and python 3 int do the same thing, newint should probably maintain the default expected behavior.

Python 2.7.11 |Anaconda 2.5.0 (x86_64)| (default, Dec  6 2015, 18:57:58) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import numpy as np
>>> from builtins import int as newint
>>> int(np.string_('1'))
1
>>> newint(np.string_('1'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/anaconda/envs/py27/lib/python2.7/site-packages/future/types/newint.py", line 57, in __new__
    val = x.__int__()
TypeError: don't know how to convert scalar number to int
@ssolari
Copy link
Author

ssolari commented Feb 17, 2016

and even different inconsistent behavior with numpy that will cause bugs later without causing the same immediate TypeError.

>>> np.array(['1']).astype(int)
array([1])
>>> np.array(['1']).astype(newint)
array(['1'], dtype=object)

@nharada1
Copy link

I'm also seeing this issue even from conversions not from strings. For example:

>>> a = np.array([1.2])
>>> a
array([ 1.2])
>>> a.astype(int)
array([1.2], dtype=object)

@nharada1
Copy link

I'm able to work around this by casting to np.int64

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

3 participants