Skip to content

Commit

Permalink
Merge pull request #1484 from brian-team/numpy_2_compatibility
Browse files Browse the repository at this point in the history
Numpy 2 compatibility
  • Loading branch information
mstimberg committed Sep 18, 2023
2 parents c2789b2 + aa11e2b commit 2c382ca
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
run: ${{ steps.python.outputs.python-path }} -m pip install --pre -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple .
- name: Run Tests
run: |
cd $GITHUB_WORKSPACE/.. # move out of the workspace to avoid direct import
${{ steps.python.outputs.python-path }} -Wd $GITHUB_WORKSPACE/dev/continuous-integration/run_test_suite.py
cd ${{ github.workspace }}/.. # move out of the workspace to avoid direct import
${{ steps.python.outputs.python-path }} -Wd ${{ github.workspace }}/dev/continuous-integration/run_test_suite.py
env:
DEPRECATION_ERROR: true
AGENT_OS: ${{runner.os}}
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ Dependencies
------------
The following packages need to be installed to use Brian 2 (cf. `setup.py <setup.py>`_):

* Python >= 3.7
* NumPy >=1.17
* Python >= 3.9
* NumPy >=1.21
* SymPy >= 1.2
* Cython >= 0.29
* Cython >= 0.29.21
* PyParsing
* Jinja2 >= 2.7
* setuptools >= 24.2
* setuptools >= 61
* py-cpuinfo (only required on Windows)

For full functionality, you might also want to install:
Expand Down
8 changes: 4 additions & 4 deletions brian2/core/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_dtype(obj):
if hasattr(obj, "dtype"):
return obj.dtype
else:
return np.obj2sctype(type(obj))
return np.dtype(type(obj))


def get_dtype_str(val):
Expand Down Expand Up @@ -353,11 +353,11 @@ def __init__(self, name, value, dimensions=DIMENSIONLESS, owner=None):
# Use standard Python types if possible for numpy scalars
if getattr(value, "shape", None) == () and hasattr(value, "dtype"):
numpy_type = value.dtype
if np.can_cast(numpy_type, np.int_):
if np.can_cast(numpy_type, int):
value = int(value)
elif np.can_cast(numpy_type, np.float_):
elif np.can_cast(numpy_type, float):
value = float(value)
elif np.can_cast(numpy_type, np.complex_):
elif np.can_cast(numpy_type, complex):
value = complex(value)
elif value is np.True_:
value = True
Expand Down
2 changes: 1 addition & 1 deletion brian2/groups/neurongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ def __setattr__(self, key, value):
if value.index is not None:
try:
index_array = np.asarray(value.index)
if not np.issubsctype(index_array.dtype, int):
if not np.issubdtype(index_array.dtype, int):
raise TypeError()
except TypeError:
raise TypeError(
Expand Down
9 changes: 7 additions & 2 deletions brian2/units/fundamentalunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
from warnings import warn

import numpy as np
from numpy import VisibleDeprecationWarning

try:
from numpy.exceptions import VisibleDeprecationWarning # numpy 2.x
except ImportError:
from numpy import VisibleDeprecationWarning # numpy 1.x

from sympy import latex

__all__ = [
Expand Down Expand Up @@ -1065,7 +1070,7 @@ def __new__(cls, arr, dim=None, dtype=None, copy=False, force_quantity=False):
subarr = np.array(arr, dtype=dtype, copy=copy).view(cls)

# We only want numerical datatypes
if not np.issubclass_(np.dtype(subarr.dtype).type, (np.number, np.bool_)):
if not issubclass(np.dtype(subarr.dtype).type, (np.number, np.bool_)):
raise TypeError("Quantities can only be created from numerical data.")

# If a dimension is given, force this dimension
Expand Down
4 changes: 2 additions & 2 deletions dev/continuous-integration/run_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
test_in_parallel=in_parallel,
reset_preferences=reset_preferences,
float_dtype=float_dtype,
test_GSL=True,
test_GSL=False,
sphinx_dir=sphinx_dir,
additional_args=args)
else:
Expand All @@ -73,7 +73,7 @@
test_in_parallel=in_parallel,
reset_preferences=reset_preferences,
float_dtype=float_dtype,
test_GSL=True,
test_GSL=False,
sphinx_dir=sphinx_dir,
additional_args=args)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
requires-python = '>=3.9'
dependencies = [
'numpy>=1.21',
'cython>=0.29',
'cython>=0.29.21',
'sympy>=1.2',
'pyparsing',
'jinja2>=2.7',
Expand Down

0 comments on commit 2c382ca

Please sign in to comment.