Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

rth
Copy link
Member

@rth rth commented May 31, 2019

Closes #5786

On the discussion whether,

  • isinstance(x, (numbers.Integral, np.integer))
  • isinstance(x, six.integer_types)

should be used for testing integer dtype (including np.integer), a better choice is to use isinstance(x, numbers.Integral) as mentionned in #5786 (comment)

>>> import numpy as np
>>> import numbers
>>> x = np.int64(2)
>>> x
2
>>> type(x)
<class 'numpy.int64'>
>>> isinstance(x, numbers.Integral)
True

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

benchmarks/bench_plot_nmf.py uses from sklearn.decomposition.nmf import INTEGER_TYPES, which should be updated.

@rth
Copy link
Member Author

rth commented Jun 3, 2019

Good point, thanks -- fixed.

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

lgtm.
(failing tests are unrelated)

@jnothman
Copy link
Member

Although I do recall vaguely that some numpy int types behaved differently to others...

@rth
Copy link
Member Author

rth commented Jun 11, 2019

Although I do recall vaguely that some numpy int types behaved differently to others...

Maybe some time ago in numpy? Both on latest numpy and v1.11 (latest supported verson) it works for all numpy int types,

>>> import numpy as np
>>> import numbers
>>> isinstance(np.int_(2), numbers.Integral)
True
>>> isinstance(np.intc(2), numbers.Integral)
True
>>> isinstance(np.int64(2), numbers.Integral)
True
>>> isinstance(np.uint8(2), numbers.Integral)
True

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.

isinstance(x, (numbers.Integral, np.integer)) vs isinstance(x, six.integer_types)
4 participants