python - 仅在 PyCharm 中发生的异常

标签 python pandas visual-studio-code pycharm

当我尝试在 PyCharm IDE 中调试以下代码时,我得到了'NoneType' object is not callable'。 无论是在 Visual Studio Code 中调试还是在未在 Pycharm 中调试的情况下运行代码时,我都没有遇到相同的错误。

new_dataframe = dataframe.replace("\"", "", regex = True)

此代码片段也复制了错误:

import pandas

dataframe = pandas.DataFrame()
dataframe['PMES'] = ['No', None]

new_dataframe = dataframe.replace("\"", "", regex = True)

teste = ""

这是我在 Visual Studio Code 中的 DataFrame(在 DataViewer 中看到的)

DataFrame in Visual Studio Code

这是 PyCharm 中的 DataFrame。

DataFrame in PyCharm

在同一个项目中可视化的两个 DataFrame,使用相同的代码,错误仅发生在 PyCharm 中。

更新

这是经过审查的完整 PyCharm 回溯。

Traceback (most recent call last):
  File "C:\???\???\???\???\???\???\???\conversion\tabula\__init__.py", line 133, in format_dataframe
    new_dataframe = dataframe.replace("\"", "", regex = True)
  File "C:\Users\???\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\frame.py", line 5238, in replace
    return super().replace(
  File "C:\Users\???\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\generic.py", line 6609, in replace
    new_data = self._mgr.replace(
  File "C:\Users\???\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\internals\managers.py", line 437, in replace
    return self.apply(
  File "C:\Users\???\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\internals\managers.py", line 327, in apply
    applied = getattr(b, f)(**kwargs)
  File "C:\Users\???\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\internals\blocks.py", line 686, in replace
    return self._replace_regex(to_replace, value, inplace=inplace)
  File "C:\Users\???\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\internals\blocks.py", line 759, in _replace_regex
    replace_regex(new_values, rx, value, mask)
  File "C:\Users\???\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\array_algos\replace.py", line 152, in replace_regex
    f = np.vectorize(re_replacer, otypes=[np.object_])
  File "C:\Users\???\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\lib\function_base.py", line 2120, in __init__
    otypes = ''.join([_nx.dtype(x).char for x in otypes])
  File "C:\Users\???\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\lib\function_base.py", line 2120, in <listcomp>
    otypes = ''.join([_nx.dtype(x).char for x in otypes])
TypeError: 'NoneType' object is not callable

最佳答案

这似乎是一个 known numpy bug #21008使用 Python 3.10。 PyCharm boards 上有很多关于此的投诉也。内部 numpy 讨论建议使用 numpy 1.22.4 进行修复。 .在此之前,Python 3.9.12 似乎没有这个问题。

关于python - 仅在 PyCharm 中发生的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70278509/

相关文章:

python - Pandas 数据帧 : convert Date format between two totally different formats

git - 解决 VS Code 中不显示的 merge 冲突工具栏

c - 无法向代码添加正确的错误检查

python - 如何在 MacOS X 上添加 python 模块?

python - 如何在 pandas 中创建与多个列组合的数据框列

python - 相机标定,像素方向反投影

php - 如何为 Xdebug 3.0 版本设置 VSCode launch.json?

python datetime fromtimestamp 产生值错误年份超出范围

python - Pandas Python 数据帧关联规则的事务 ID 列。

python - pandas read_csv 编码奇怪的字符