ndexbio / ndex2-client

NDEx2 Client
BSD 3-Clause "New" or "Revised" License
6 stars 6 forks source link

ndex2.create_nice_cx_from_networkx fails with numpy 1.24.X #96

Closed coleslaw481 closed 1 year ago

coleslaw481 commented 1 year ago

It looks like numpy in 1.24.X versions finally removed np.float, np.int, np.double aliases which is causing ndex2.create_nice_cx_from_networkx to fail with this error:

File ~/anaconda3/envs/bnf286/lib/python3.9/site-packages/ndex2/__init__.py:286, in create_nice_cx_from_networkx(G)
    283 if k == 'name' or k == 'represents':
    284     continue
--> 286 use_this_value, attr_type = cx_builder._infer_data_type(v, split_string=False)
    288 # This might go away, waiting on response to
    289 # https://ndexbio.atlassian.net/browse/UD-2181
    290 if k == 'citation' and not isinstance(use_this_value, list):

File ~/anaconda3/envs/bnf286/lib/python3.9/site-packages/ndex2cx/nice_cx_builder.py:471, in NiceCXBuilder._infer_data_type(self, val, split_string)
    468         elif ';' in val:
    469             val = val.split(';')
--> 471 if isinstance(val, float) or isinstance(val, np.float) or isinstance(val, np.double):
    472     if math.isnan(val):
    473         # do something (skip?)
    474         val = None

File ~/anaconda3/envs/bnf286/lib/python3.9/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':

AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:

The release note about the removal of the aliases: https://numpy.org/devdocs/release/1.24.0-notes.html#expired-deprecations

The deprecation message on numpy: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

coleslaw481 commented 1 year ago

Fixed in 3.5.1 by removing numpy alias references since they no longer exist in newer versions of numpy