mdbartos / pysheds

:earth_americas: Simple and fast watershed delineation in python.
GNU General Public License v3.0
717 stars 196 forks source link

Fix for bincount type touchyness #122

Open AlienAtSystem opened 4 years ago

AlienAtSystem commented 4 years ago

np.bincount has at some point become extremely selective about its input type, accepting only 'int32' and nothing else.

coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 292


Totals Coverage Status
Change from base Build 291: 0.0%
Covered Lines: 2028
Relevant Lines: 2489

💛 - Coveralls
mdbartos commented 4 years ago

Interesting. What version of numpy are you using? I'm on 1.18.3 and the following still seem to work:

import numpy as np
x = np.random.randint(100, size=1000, dtype=np.int64)
_ = np.bincount(x)
x = np.random.randint(100, size=1000, dtype=np.int16)
_ = np.bincount(x)
x = np.random.randint(100, size=1000, dtype=np.uint16)
_ = np.bincount(x)
AlienAtSystem commented 4 years ago

I'm using numpy 1.19.0 in Python 3.8.3 in an Ipython 7.15.0 console and get the following:

import numpy as np
x = np.random.randint(100, size=1000, dtype=np.int64)
_ = np.bincount(x)
x = np.random.randint(100, size=1000, dtype=np.int16)
_ = np.bincount(x)
x = np.random.randint(100, size=1000, dtype=np.uint16)
_ = np.bincount(x)
Traceback (most recent call last):

  File "<ipython-input-1-015b31e77d51>", line 3, in <module>
    _ = np.bincount(x)

  File "<__array_function__ internals>", line 5, in bincount

TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'
mdbartos commented 4 years ago

Just tested again with numpy 1.19.0, python 3.8.3 and ipython 7.13.0. Still no exception on my side.

I'm running on manjaro linux using the openblas library as the backend (you can check your backend using np.show_config()).

Is it possible you are using a 32-bit version of either python/numpy or got 64/32 bit versions mixed together?