sliced
sliced copied to clipboard
Fixing AttributeError in slice_indicator initialization
The issue was related to an AttributeError
raised in the code when initializing the slice_indicator
variable. The error occurred due to the usage of np.int
as the dtype argument in the np.ones()
function. In earlier versions of NumPy, np.int
was a deprecated alias for the built-in int
type. However, starting from NumPy 1.20, these aliases were removed.
To resolve the issue, the code was modified by changing the dtype argument from np.int
to np.int64
to specify the desired precision explicitly. The modified code snippet looks as follows:
# turn partitions into an indicator
slice_indicator = np.ones(y.shape[0], dtype=np.int64)
This change ensures compatibility with the latest versions of NumPy and resolves the AttributeError
related to the use of np.int
in the code. The modified code should now execute without any errors.
By making this fix, the issue has been resolved, and the code functions as intended, initializing the slice_indicator
variable with the correct dtype.
@rafe-sh I noticed there is another np.int
in sliced.datasets
as well.
https://github.com/joshloyal/sliced/blob/243bde236d8c615f9563279a0a2095e2fa2f4650/sliced/datasets/base.py#L17
@joshloyal May I kindly ask if there is any plan for releasing a new version including this fix that @rafe-sh has made? Anyway, I sincerely thank you for making this repository!
A quick fix for this error is to add one line before using sliced
:
import numpy as np
np.int = np.int64
Of course, this is an ad-hoc solution. Hope the authors can merge this commit soon.