Skip to content

Commit

Permalink
remove obsolete numpy aliases np.bool and np.float (#1322)
Browse files Browse the repository at this point in the history
* remove obsolete numpy aliases `np.bool` and `np.float`

This basically fixes the following error that many people encountered:

```
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.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. Did you mean: 'float_'?
```

Migth not work with veeery old versions of numpy but I guess that requiring
>=1.20 is quite safe nowadays.

Ref.:
matthiaskoenig/fbc_curation#98

* add the changelog entry

* fix flake8 warning

* fix up the release notes a bit

---------

Co-authored-by: Christian Diener <ch.diener@gmail.com>
  • Loading branch information
exaexa and cdiener committed Mar 27, 2023
1 parent 93fb0e9 commit f3e8414
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 7 additions & 1 deletion release-notes/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
## New features

## Fixes
[#1300](https://github.com/opencobra/cobrapy/pull/1312)- Fixed issue where reaction bounds were being overwritten by global model min/max values when writing sbml model to file

Fixed an issue where reaction bounds were being overwritten by global model min/max values
when writing sbml model to file. See [#1300](https://github.com/opencobra/cobrapy/pull/1312).

Fix an issue where [`runfrog`](https://github.com/matthiaskoenig/fbc_curation/issues/98) does
not work via github actions or local installation by removing the use of obsolete numpy
aliases for `float` and `bool`.

## Other

Expand Down
4 changes: 1 addition & 3 deletions src/cobra/core/dictlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
Union,
)

import numpy as np

from .object import Object


Expand Down Expand Up @@ -457,7 +455,7 @@ def __getitem__(
selection._extend_nocheck(list.__getitem__(self, i))
return selection
elif hasattr(i, "__len__"):
if len(i) == len(self) and isinstance(i[0], (bool, np.bool)):
if len(i) == len(self) and isinstance(i[0], (bool, bool)):
selection = self.__class__()
result = (o for j, o in enumerate(self) if i[j])
selection._extend_nocheck(result)
Expand Down
8 changes: 4 additions & 4 deletions src/cobra/io/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@


def _fix_type(
value: Union[str, np.float, np.bool, Set, Dict]
value: Union[str, float, bool, Set, Dict]
) -> Union[str, float, bool, List, OrderedDict]:
"""Convert possible types to correct Python types.
Parameters
----------
value : str, np.float, np.bool, set, dict
value : str, float, bool, set, dict
The value to fix type for.
Returns
Expand All @@ -86,9 +86,9 @@ def _fix_type(
# Because numpy floats can not be pickled to json
if isinstance(value, str):
return str(value)
if isinstance(value, np.float):
if isinstance(value, float):
return float(value)
if isinstance(value, np.bool):
if isinstance(value, bool):
return bool(value)
if isinstance(value, set):
return list(value)
Expand Down

0 comments on commit f3e8414

Please sign in to comment.