-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Hello,
I'm getting
AttributeError: module 'numpy' has no attribute 'NAN'Running this code:
import spinmob as sm
import numpy as np
x_1 = np.linspace(0, 10, 100)
y_1 = np.cos(x_1)
f = sm.data.fitter()
f.set_functions('A*cos(k*x+p)', 'A,k,p')
f.set_data(x_1, y_1, 0.3).fit()As shown below, I am on the latest pip version of Spinmob, 3.10.1.
This issue was acknowledged in f72e68e with the addition of:
#numpy.NAN = numpy.nan # Terrible thing we have to do until some libraries catch up with deprecation (added 2025-04-07)This isn't in the latest pip version, but even in the latest source, it was introduced commented out. Manually adding this, uncommented, to my __init__.py solves the issue, and appears otherwise harmless. Perhaps this line could be uncommented and then pip could be updated.
I've added a pull request with only this change, so that it can be one-click merged, if so desired.
More information
I'm on Ubuntu, with python installed through apt, not conda. I'm using a VSCode ipynb notebook, on Python 3.12.3, with relevant packages:
ipykernel 6.30.1
ipython 9.6.0
jupyter_client 8.6.3
jupyter_core 5.8.1
kiwisolver 1.4.9
lmfit 1.3.4
matplotlib 3.10.7
matplotlib-inline 0.1.7
McPhysics 1.5.16
numpy 2.3.3
pip 24.0
scipy 1.16.2
Spinmob 3.10.1
And here is the full traceback:
AttributeError Traceback (most recent call last)
File ~/.venvs/general/lib/python3.12/site-packages/IPython/core/formatters.py:770, in PlainTextFormatter.call(self, obj)
763 stream = StringIO()
764 printer = pretty.RepresentationPrinter(stream, self.verbose,
765 self.max_width, self.newline,
766 max_seq_length=self.max_seq_length,
767 singleton_pprinters=self.singleton_printers,
768 type_pprinters=self.type_printers,
769 deferred_pprinters=self.deferred_printers)
--> 770 printer.pretty(obj)
771 printer.flush()
772 return stream.getvalue()
File ~/.venvs/general/lib/python3.12/site-packages/IPython/lib/pretty.py:411, in RepresentationPrinter.pretty(self, obj)
400 return meth(obj, self, cycle)
401 if (
402 cls is not object
403 # check if cls defines repr
(...) 409 and callable(_safe_getattr(cls, "repr", None))
410 ):
--> 411 return _repr_pprint(obj, self, cycle)
413 return _default_pprint(obj, self, cycle)
414 finally:
File ~/.venvs/general/lib/python3.12/site-packages/IPython/lib/pretty.py:786, in repr_pprint(obj, p, cycle)
784 """A pprint that just redirects to the normal repr function."""
785 # Find newlines and replace them with p.break()
--> 786 output = repr(obj)
787 lines = output.splitlines()
788 with p.group():
File ~/.venvs/general/lib/python3.12/site-packages/spinmob/_data.py:1942, in fitter.repr(self)
1937 s = s + "\nINPUT PARAMETERS\n"
1939 # If we do have data, give mor information
1940 else:
1941 s = s + "\nINPUT PARAMETERS (reduced chi^2 = {:s}, {} DOF)\n".format(
-> 1942 self._format_value_error(self.get_reduced_chi_squared(self.p_in),
1943 _n.sqrt(_n.divide(2.0,self.get_degrees_of_freedom()))),
1944 self.get_degrees_of_freedom())
1946 # Always print the guess parameters
1947 for pname in self.p_in:
File ~/.venvs/general/lib/python3.12/site-packages/spinmob/_data.py:2600, in fitter._format_value_error(self, v, e, pm)
2595 """
2596 Returns a string v +/- e with the right number of sig figs.
2597 """
2598 # If we have weird stuff
2599 if not _functions.is_a_number(v) or not _functions.is_a_number(e)
-> 2600 or v in [_n.inf, _n.nan, _n.NAN] or e in [_n.inf, _n.nan, _n.NAN]:
2601 return str(v)+pm+str(e)
2603 # Normal values.
File ~/.venvs/general/lib/python3.12/site-packages/numpy/init.py:795, in getattr(attr)
792 import numpy.char as char
793 return char.chararray
--> 795 raise AttributeError(f"module {name!r} has no attribute {attr!r}")
AttributeError: module 'numpy' has no attribute 'NAN'Metadata
Metadata
Assignees
Labels
No labels