Skip to content

ndimage._ni_support._normalize_sequence() fails with numpy.int64 #4106

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

Closed
pllim opened this issue Oct 27, 2014 · 2 comments
Closed

ndimage._ni_support._normalize_sequence() fails with numpy.int64 #4106

pllim opened this issue Oct 27, 2014 · 2 comments
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.ndimage
Milestone

Comments

@pllim
Copy link
Contributor

pllim commented Oct 27, 2014

Windows 7 64-bit with Anaconda. Traceback in attached screenshot.

>>> import numpy as np
>>> import scipy
>>> scipy.__version__
'0.14.0'
>>> from scipy.ndimage._ni_support import _normalize_sequence
>>> x = np.int64(21)
>>> _normalize_sequence(x, 0)

Might be related to numpy/numpy#2951 ?
untitled

@ev-br
Copy link
Member

ev-br commented Nov 3, 2014

The issue seems to be with non-native numpy integer types not being recognized as six.integer_types:

>>> from scipy.lib.six import integer_types
>>> integer_types
(<type 'int'>, <type 'long'>)
>>> isinstance(np.int64(1), integer_types)
True
>>> isinstance(np.int32(1), integer_types)
False

Meanwhile, this is not numpy/numpy#2951 :

>>> isinstance(np.int32(1), numbers.Integral)
True

This is for python 2.7, numpy 1.9.1 on a 64-bit Ubuntu. On a 32-bit Windows7 Anaconda distribution, it's the revese: np.int32 is OK, but np.int64 is not.

To fix this, we can either add numpy integer types to scipy.lib.six.integer_types or expand https://github.com/scipy/scipy/blob/master/scipy/ndimage/_ni_support.py#L60
to something like:

if isinstance(input, integer_types + (float,)) or np.issubdtype(np.asarray(intput).dtype, np.integer):

(as per http://stackoverflow.com/questions/22471644/how-do-i-check-if-a-numpy-dtype-is-integral).

@ev-br ev-br added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.ndimage labels Nov 3, 2014
person142 added a commit to person142/scipy that referenced this issue Oct 31, 2015
The function ndimage.filters.gaussian_filter has a parameter sigma
which expects a scalar or sequence of scalars. But when passed a numpy
int type it fails. The same happens for BPoly.from_derivatives with
the parameter orders. See the discussion on scipygh-5430 and scipygh-4106;
closes scipygh-5430 and scipygh-4106.
person142 added a commit to person142/scipy that referenced this issue Nov 15, 2015
@ev-br
Copy link
Member

ev-br commented Nov 15, 2015

Fixed in #5444, closing.

@ev-br ev-br added this to the 0.17.0 milestone Nov 15, 2015
@ev-br ev-br closed this as completed Nov 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.ndimage
Projects
None yet
Development

No branches or pull requests

2 participants