Skip to content

Commit

Permalink
Numpy 2.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mwshinn committed Jun 21, 2024
1 parent cf1eb2d commit 540b957
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pyddm/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def gddm(drift=0, noise=1, bound=1, nondecision=0, starting_position=0, mixture_

for name,p in parameters.items():
assert name not in ["x", "t", "T", "dx"], f"Parameters cannot be named 'x', 't', 'T', or 'dx'. Invalid name '{name}'."
assert isinstance(p, (int,float,np.float_,np.int_)) or (isinstance(p, tuple) and len(p) == 2 and isinstance(p[0], (float,int,np.int_,np.float_)) and isinstance(p[1], (float,int,np.int_,np.float_))), f"Parameters must be a single number or a tuple of numbers (representing a range for fitting). Invalid parameter '{name}'."
assert isinstance(p, (int,float,np.floating,np.integer)) or (isinstance(p, tuple) and len(p) == 2 and isinstance(p[0], (float,int,np.integer,np.floating)) and isinstance(p[1], (float,int,np.integer,np.floating))), f"Parameters must be a single number or a tuple of numbers (representing a range for fitting). Invalid parameter '{name}'."
assert name.isidentifier() and not keyword.iskeyword(name), f"Parameter names must be valid names for variables in Python. Invalid parameter name '{name}'."

# Either the fittable or the constant value
Expand All @@ -888,7 +888,7 @@ def _parse_dep(val, name, special="xt"):
val = eval(f"lambda {val}: {val}")
if val in parameters.keys():
return "val",None,_fittables[val]
elif isinstance(val, (int,float,np.float_,np.int_)):
elif isinstance(val, (int,float,np.floating,np.integer)):
return "val",None,val
elif hasattr(val, "__call__"):
sig = inspect.getfullargspec(val)
Expand Down
4 changes: 1 addition & 3 deletions pyddm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def solve_analytical(self, conditions={}, force_python=False):
if isinstance(self.get_dependence('IC'),(ICPoint, ICPointRatio)):
ic = self.IC(conditions=conditions)
assert np.count_nonzero(ic)==1, "Cannot solve analytically for models with non-point initial conditions"
shift = np.flatnonzero(ic) / (len(ic) - 1) #rescale to proprotion of total bound height
shift = np.flatnonzero(ic)[0] / (len(ic) - 1) #rescale to proprotion of total bound height
else:
shift = None

Expand All @@ -660,9 +660,7 @@ def solve_analytical(self, conditions={}, force_python=False):
force_python=force_python)

## Remove some abnormalities such as NaN due to trivial reasons.
anal_pdf_choice_upper[anal_pdf_choice_upper==np.NaN] = 0. # FIXME Is this a bug? You can't use == to compare nan to nan...
anal_pdf_choice_upper[0] = 0.
anal_pdf_choice_lower[anal_pdf_choice_lower==np.NaN] = 0.
anal_pdf_choice_lower[0] = 0.

# Fix numerical errors
Expand Down
4 changes: 2 additions & 2 deletions pyddm/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def pt(x): # Pythonic types
arr = np.asarray(x, dtype=object)
# The following is somewhat of a hack to get rid of object arrays
# when a condition is not a number (e.g. string or tuple)
if len(arr) > 0 and not isinstance(arr[0], (float, int, np.float_, np.int_)):
if len(arr) > 0 and not isinstance(arr[0], (float, int, np.floating, np.integer)):
return arr
arr = np.asarray(arr.tolist())
try:
Expand Down Expand Up @@ -271,7 +271,7 @@ def pt(x): # Pythonic types
arr = np.asarray(x, dtype=object)
# The following is somewhat of a hack to get rid of object arrays
# when a condition is not a number (e.g. string or tuple)
if len(arr) > 0 and not isinstance(arr[0], (float, int, np.float_, np.int_)):
if len(arr) > 0 and not isinstance(arr[0], (float, int, np.floating, np.integer)):
return arr
arr = np.asarray(arr.tolist())
try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
sources=['pyddm/csolve.c'],
include_dirs=[np.get_include()],
)],
install_requires = ['numpy >= 1.9.2', 'scipy >= 0.16', 'matplotlib', 'paranoid-scientist >= 0.2.1'],
install_requires = ['numpy >= 1.9.2', 'scipy >= 0.16', 'matplotlib', 'paranoid-scientist >= 0.2.3', 'pandas'],
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
Expand Down

0 comments on commit 540b957

Please sign in to comment.