如何修复 NumPy .dtype“NoneType”错误

Han*_*ans 11 numpy python-3.x

我正在 PyCharm 调试模式下运行以下 Python 代码。

import numpy as np, pandas as pd, numpy.polynomial.chebyshev as chebyshev
from pathlib import Path

home = str(Path.home())

directory = '/Downloads'
d = pd.read_csv(home+directory+'/data.csv')

np.random.seed(0)
nData = 4
data = np.random.randn(nData,2)
z = data[:,0]
y = data[:,1]

coef = chebyshev.chebfit(z,y,3)
Run Code Online (Sandbox Code Playgroud)

我遇到以下错误消息:

TypeError: 'NoneType' object is not callable
Run Code Online (Sandbox Code Playgroud)

但是,如果我注释掉“d = ...”行,一切都会正常。更奇怪的是,两个版本在运行模式下都运行良好。这里发生了什么?

错误的堆栈跟踪:

/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --cmd-line --multiproc --qt-support=auto --client 127.0.0.1 --port 65032 --file /Users/PycharmProjects/pythonProject/trial.py
warning: PYDEVD_USE_CYTHON environment variable is set to 'NO'. Frame evaluator will be also disabled because it requires Cython extensions to be enabled in order to operate correctly.
/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py:1844: DeprecationWarning: currentThread() is deprecated, use current_thread() instead
  dummy_thread = threading.currentThread()
Connected to pydev debugger (build 212.5457.59)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/getlimits.py", line 384, in __new__
    dtype = numeric.dtype(dtype)
TypeError: 'NoneType' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/PycharmProjects/pythonProject/trial.py", line 16, in <module>
    coef0 = chebyshev.chebfit(z0,y0,4)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/polynomial/chebyshev.py", line 1670, in chebfit
    return pu._fit(chebvander, x, y, deg, rcond, full, w)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/polynomial/polyutils.py", line 650, in _fit
    rcond = len(x)*np.finfo(x.dtype).eps
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/getlimits.py", line 387, in __new__
    dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable

Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

mtd*_*mtd 13

请升级到 pandas >= 1.4.3 以解决此问题。您需要降级到 Python 3.9 或升级到 pandas 1.4.3

一个真正的错误(截至 2022 年 4 月 14 日),已通过以下方式修复:


has*_*abi 6

这个答案很棒。但应该更新。

简短回答:

升级熊猫 -->v1.4.3

你应该升级到v1.4.3pandas。然后代码现在在调试器中的行为符合预期。