corels / pycorels

Public home of pycorels, the python binding to CORELS
GNU General Public License v3.0
75 stars 14 forks source link

Numpy Version Issue: np.bool depreciated #23

Open nickeubank opened 1 year ago

nickeubank commented 1 year ago

I think related to #21

Getting:

AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
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

Full messages:

AttributeError                            Traceback (most recent call last)
Cell In[5], line 5
      3 defendants = defendants[defendants.is_recid != -1]
      4 y, X = patsy.dmatrices("is_recid ~ sex + age + juv_fel_count + priors_count", defendants)
----> 5 CorelsClassifier().fit(X, y.squeeze())

File [~/opt/miniconda3/lib/python3.10/site-packages/corels/corels.py:157](https://file+.vscode-resource.vscode-cdn.net/Users/nce8/github/unifyingdatascience_solutions/source/exercises/~/opt/miniconda3/lib/python3.10/site-packages/corels/corels.py:157), in CorelsClassifier.fit(self, X, y, features, prediction_name)
    154 if not isinstance(prediction_name, str):
    155     raise TypeError("Prediction name must be a string, got: " + str(type(prediction_name)))
--> 157 label = check_array(y, ndim=1)
    158 labels = np.stack([ np.invert(label), label ])
    159 samples = check_array(X, ndim=2)

File [~/opt/miniconda3/lib/python3.10/site-packages/corels/utils.py:17](https://file+.vscode-resource.vscode-cdn.net/Users/nce8/github/unifyingdatascience_solutions/source/exercises/~/opt/miniconda3/lib/python3.10/site-packages/corels/utils.py:17), in check_array(x, ndim)
     13 if ndim and ndim != x.ndim:
     14     raise ValueError("Array must be " + str(ndim) + "-dimensional in shape, got " + str(x.ndim) +
     15                      " dimensions instead")
---> 17 asbool = x.astype(np.bool)
     19 if not np.array_equal(x, asbool):
     20     raise ValueError("Array must contain only binary members (0 or 1), got " + str(x));

File [~/opt/miniconda3/lib/python3.10/site-packages/numpy/__init__.py:305](https://file+.vscode-resource.vscode-cdn.net/Users/nce8/github/unifyingdatascience_solutions/source/exercises/~/opt/miniconda3/lib/python3.10/site-packages/numpy/__init__.py:305), in __getattr__(attr)
    300     warnings.warn(
    301         f"In the future `np.{attr}` will be defined as the "
    302         "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    304 if attr in __former_attrs__:
--> 305     raise AttributeError(__former_attrs__[attr])
    307 # Importing Tester requires importing all of UnitTest which is not a
    308 # cheap import Since it is mainly used in test suits, we lazy import it
    309 # here to save on the order of 10 ms of import time for most users
    310 #
    311 # The previous way Tester was imported also had a side effect of adding
    312 # the full `numpy.testing` namespace
    313 if attr == 'testing':
RickSrick commented 1 year ago

I found the same problem as yours. Reading the Release Note of Numpy 1.20 (numpy) it is told to:

replace np.bool with np.bool_

If you make the changes to the following files:

you solve the problem.happy to be helpful đŸ˜„