MrOlm / inStrain

Bioinformatics program inStrain
MIT License
149 stars 33 forks source link

AttributeError: module 'numpy' has no attribute 'bool'. #154

Closed HaimAshk closed 1 year ago

HaimAshk commented 1 year ago

Hi,

Following installation using either pip or conda I get the following error:

.local/lib/python3.8/site-packages/pandas/_testing.py:24: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.
  import pandas._libs.testing as _testing
Traceback (most recent call last):
  File "InStrain_1.75/bin/inStrain", line 19, in <module>
    import inStrain.controller
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/controller.py", line 13, in <module>
    import pandas as pd
  File ".local/lib/python3.8/site-packages/pandas/__init__.py", line 180, in <module>
    import pandas.testing
  File "local/lib/python3.8/site-packages/pandas/testing.py", line 5, in <module>
    from pandas._testing import (
  File ".local/lib/python3.8/site-packages/pandas/_testing.py", line 24, in <module>
    import pandas._libs.testing as _testing
  File "pandas/_libs/testing.pyx", line 10, in init pandas._libs.testing
  File "InStrain_1.75/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
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

My env is as follow:

python -V
Python 3.8.16

# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
_openmp_mutex             5.1                       1_gnu  
asteval                   0.9.30                   pypi_0    pypi
biopython                 1.74                     pypi_0    pypi
ca-certificates           2023.05.30           h06a4308_0  
contourpy                 1.1.0                    pypi_0    pypi
cycler                    0.11.0                   pypi_0    pypi
cython                    0.29.35                  pypi_0    pypi
exceptiongroup            1.1.1                    pypi_0    pypi
fonttools                 4.40.0                   pypi_0    pypi
h5py                      3.9.0                    pypi_0    pypi
importlib-resources       5.12.0                   pypi_0    pypi
iniconfig                 2.0.0                    pypi_0    pypi
instrain                  1.7.5                    pypi_0    pypi
kiwisolver                1.4.4                    pypi_0    pypi
ld_impl_linux-64          2.38                 h1181459_1  
libffi                    3.4.4                h6a678d5_0  
libgcc-ng                 11.2.0               h1234567_1  
libgomp                   11.2.0               h1234567_1  
libstdcxx-ng              11.2.0               h1234567_1  
lmfit                     1.2.1                    pypi_0    pypi
matplotlib                3.7.1                    pypi_0    pypi
ncurses                   6.4                  h6a678d5_0  
networkx                  3.1                      pypi_0    pypi
numpy                     1.24.3                   pypi_0    pypi
openssl                   3.0.8                h7f8727e_0  
packaging                 23.1                     pypi_0    pypi
pillow                    9.5.0                    pypi_0    pypi
pip                       23.1.2           py38h06a4308_0  
pluggy                    1.2.0                    pypi_0    pypi
psutil                    5.9.5                    pypi_0    pypi
pyparsing                 3.1.0                    pypi_0    pypi
pysam                     0.21.0                   pypi_0    pypi
pytest                    7.3.2                    pypi_0    pypi
python                    3.8.16               h955ad1f_4  
readline                  8.2                  h5eee18b_0  
scipy                     1.10.1                   pypi_0    pypi
seaborn                   0.12.2                   pypi_0    pypi
setuptools                67.8.0           py38h06a4308_0  
sqlite                    3.41.2               h5eee18b_0  
tk                        8.6.12               h1ccaba5_0  
tomli                     2.0.1                    pypi_0    pypi
tqdm                      4.65.0                   pypi_0    pypi
uncertainties             3.1.7                    pypi_0    pypi
wheel                     0.38.4           py38h06a4308_0  
xz                        5.4.2                h5eee18b_0  
zipp                      3.15.0                   pypi_0    pypi
zlib                      1.2.13               h5eee18b_0  

Can you please suggest a solution?

Thanks! Haim

MrOlm commented 1 year ago

Hi @HaimAshk - what a silly numpy bug. The simplest fix would be to install an older version of numpy- for example with the command pip install numpy==1.23

Best, Matt

HaimAshk commented 1 year ago

Dear @MrOlm,

Thanks a lot for the quick response! I now installed an older version of numpy as you suggested. inStrain -h seems to run now, but I get a different error when analyzing the dataset (a metagenomic sample against a single isolate genome):

inStrain profile S1MetagenomicR1R2_vs_isolate_ONT.sam isolate.fasta -o S1MetagenomicR1R2_vs_isolate_ONT.IS -p 6
Traceback (most recent call last):
  File "InStrain_1.75/bin/inStrain", line 31, in <module>
    inStrain.controller.Controller().main(args)
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/controller.py", line 54, in main
    self.profile_operation(args)
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/controller.py", line 86, in profile_operation
    ProfileController(args).main()
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/controller.py", line 149, in main
    self.validate_arguments()
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/controller.py", line 187, in validate_arguments
    ISP = inStrain.SNVprofile.SNVprofile(outbase)
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/SNVprofile.py", line 44, in __init__
    self._initialize_attributes()
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/SNVprofile.py", line 580, in _initialize_attributes
    self.store('location', self.location, 'value', 'Location of SNVprofile object')
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/SNVprofile.py", line 58, in store
    adb = pd.DataFrame({'value':value, 'type':type, 'description':description}, index=[name])
  File ".local/lib/python3.8/site-packages/pandas/core/frame.py", line 435, in __init__
    mgr = init_dict(data, index, columns, dtype=dtype)
  File ".local/lib/python3.8/site-packages/pandas/core/internals/construction.py", line 254, in init_dict
    return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
  File ".local/lib/python3.8/site-packages/pandas/core/internals/construction.py", line 69, in arrays_to_mgr
    arrays = _homogenize(arrays, index, dtype)
  File ".local/lib/python3.8/site-packages/pandas/core/internals/construction.py", line 322, in _homogenize
    val = sanitize_array(
  File ".local/lib/python3.8/site-packages/pandas/core/construction.py", line 465, in sanitize_array
    subarr = construct_1d_arraylike_from_scalar(value, len(index), dtype)
  File ".local/lib/python3.8/site-packages/pandas/core/dtypes/cast.py", line 1452, in construct_1d_arraylike_from_scalar
    subarr = np.empty(length, dtype=dtype)
TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type

Is it related to the numpy error? Anything I did wrong (I followed the tutorial) ?

Thanks! Haim

MrOlm commented 1 year ago

Hi @HaimAshk - that seems to be a pandas error. Try upgrading pandas with pip install pandas --upgrade

HaimAshk commented 1 year ago

Thanks, Did it now (to panda version: 2.0.2) Still (a different) error:

Traceback (most recent call last):
  File "InStrain_1.75/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 3652, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas/_libs/index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'version'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "InStrain_1.75/bin/inStrain", line 31, in <module>
    inStrain.controller.Controller().main(args)
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/controller.py", line 54, in main
    self.profile_operation(args)
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/controller.py", line 86, in profile_operation
    ProfileController(args).main()
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/controller.py", line 149, in main
    self.validate_arguments()
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/controller.py", line 187, in validate_arguments
    ISP = inStrain.SNVprofile.SNVprofile(outbase)
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/SNVprofile.py", line 44, in __init__
    self._initialize_attributes()
  File "InStrain_1.75/lib/python3.8/site-packages/inStrain/SNVprofile.py", line 595, in _initialize_attributes
    if not same_versions(Adb.loc['version', 'value'], __version__):
  File "InStrain_1.75/lib/python3.8/site-packages/pandas/core/indexing.py", line 1096, in __getitem__
    return self.obj._get_value(*key, takeable=self._takeable)
  File "InStrain_1.75/lib/python3.8/site-packages/pandas/core/frame.py", line 3877, in _get_value
    row = self.index.get_loc(index)
  File "InStrain_1.75/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 3654, in get_loc
    raise KeyError(key) from err
KeyError: 'version'

Hopefully, we make progress ;-)

Thanks for the support!

MrOlm commented 1 year ago

It seems like you're running the program on a previously-failed inStrain output directory. Delete all inStrain output and try again. If that doesn't work, lmk the command you're running

HaimAshk commented 1 year ago

Thanks a lot!!! You were correct; sorry, my bad. Using an empty output directory solved the issue. Thanks!!