python - Visual Studio Code Python 中的 "Assertion ' __builtin_expect(__n < this->size(), true) ' failed"错误

标签 python c++ visual-studio-code fedora

我知道已经有很多关于断言失败的内容了。但没有一个对我有用。听我说。

这是代码:

import numpy as np, pandas as pd
from outliertree import OutlierTree

### random data frame with an obvious outlier
nrows = 100
np.random.seed(1)
df = pd.DataFrame({
    "numeric_col1" : np.r_[np.random.normal(size = nrows - 1), np.array([float(1e6)])],
    "numeric_col2" : np.random.gamma(1, 1, size = nrows),
    "categ_col"    : np.random.choice(['categA', 'categB', 'categC'], size = nrows)
    })

### test data frame with another obvious outlier
df_test = pd.DataFrame({
    "numeric_col1" : np.random.normal(size = nrows),
    "numeric_col2" : np.r_[np.array([float(-1e6)]), np.random.gamma(1, 1, size = nrows - 1)],
    "categ_col"    : np.random.choice(['categA', 'categB', 'categC'], size = nrows)
    })

### fit model
outliers_model = OutlierTree()
outliers_df = outliers_model.fit(df, outliers_print = 10, return_outliers = True) # gives error

### find outliers in new data
new_outliers = outliers_model.predict(df_test)

### print outliers in readable format
outliers_model.print_outliers(new_outliers)

这是错误:

/usr/include/c++/10/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = char; _Alloc = std::allocator; std::vector<_Tp, _Alloc>::reference = char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__builtin_expect(__n < this->size(), true)' failed. Aborted (core dumped)

错误发生在行:

outliers_df = outliers_model.fit(df, outliers_print = 10, return_outliers = True)

Python 版本:

Python 3.9.2 (default, Feb 20 2021, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux

操作系统:

Fedora 5.10.12-200.fc33.x86_64

集成开发环境:

Visual Studio Code

代码在 Google Colab 中运行良好。那么为什么它只发生在 IDE 中呢?如果是设置或环境问题,我该怎么办?这是我第一次使用 Visual Studio Code。

谢谢

最佳答案

这里是该库的作者。代码中有一个错误,只有当设置定义了宏 _GLIBCXX_ASSERTIONS 时才会触发,否则不会显示。现在应该已在最新版本 (1.7.0) 中修复 - 请重试 (pip install -U outliertree),如果问题仍然存在,请在 github 问题跟踪器中发表评论。

关于python - Visual Studio Code Python 中的 "Assertion ' __builtin_expect(__n < this->size(), true) ' failed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66892158/

相关文章:

Python:为什么具有两个参数的未绑定(bind)方法的行为不同于类方法?

c++ - 追踪内存损坏的具体调试技巧/工具?

visual-studio-code - 将终端移回底部

c++ - 迭代 std::vector(没有迭代器)时使用哪种类型?

c++ - 如何在 C 中设计样式?

visual-studio-code - 为什么当我将鼠标悬停在 VS Code 上时,它会出现类似芯片/扭曲的显示?

visual-studio-code - 如何在VS Code中删除匹配的括号?

python - 如何通过分区连接 Pandas 列?

python理解合并生成all_3_digit_numbers

python - 如何将 JSON 数组添加到 DRF 响应