繁体   English   中英

Visual Studio Code Python 中的“断言 '__builtin_expect(__n < this->size(), true)' failed”错误

[英]“Assertion '__builtin_expect(__n < this->size(), true)' failed” error in Visual Studio Code Python

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

这是代码:

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]:断言 '__builtin_expect(__n < this->size(), true)' 失败。 中止(核心转储)

错误发生在以下行:

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

Python 版本:

Python 3.9.2(默认,2021 年 2 月 20 日,00:00:00)[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] 在 linux

操作系统:

Fedora 5.10.12-200.fc33.x86_64

IDE:

视觉工作室代码

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

谢谢

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

我对 OutlierTree 的了解不够,不知道如何修复错误。 但是,您看到的错误在 function std::vector::operator[]中,这是std::vector通过索引 function 访问的。 断言错误仅仅意味着您试图访问索引处大于向量长度的项目。

至于为什么你只在 VS Code 中看到这个错误,我认为这是因为断言通常只在调试模式下检查。 Google Collab 可能在没有断言的情况下在发布模式下编译 - 这并不意味着您不会访问越界项目,它只是不会捕获错误。

我建议您使用 gdb 或其他调试器来了解您尝试越界访问哪个向量,然后将堆栈跟踪附加到您的问题。 也许用 OutlierTree 提交一个错误报告——这似乎是他们可以更好地处理的事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM