joshloyal / sliced

sliced: scikit-learn compatible sufficient dimension reduction
https://joshloyal.github.io/sliced/
MIT License
21 stars 11 forks source link

AttributeError: module 'numpy' has no attribute 'int'. `np.int` was a deprecated alias for the builtin `int` #14

Open bpsut opened 1 year ago

bpsut commented 1 year ago

I was trying to run this sir.fit(X, Y) and ran into the above issue with numpy 1.24

It looks like an easy fix to swap line 119 of base.py to one of the following: slice_indicator = np.ones(y.shape[0], dtype=int) slice_indicator = np.ones(y.shape[0], dtype=int32) slice_indicator = np.ones(y.shape[0], dtype=int64)

Full AttributeError:

AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
rafe-sh commented 10 months ago

Based on the provided information, it appears that you encountered an issue with the numpy module when using the sir.fit(X, Y) line of code. The error message suggests that the module does not have an attribute called int. This issue is related to a deprecation in numpy version 1.20 where aliases for built-in types, such as np.int, were deprecated.

To fix this issue, you can swap line 119 of the base.py file with one of the following options:

slice_indicator = np.ones(y.shape[0], dtype=int)
slice_indicator = np.ones(y.shape[0], dtype=np.int32)
slice_indicator = np.ones(y.shape[0], dtype=np.int64)

The first option uses the built-in int type, which is recommended. The second and third options specify the precision by using np.int32 or np.int64 respectively.