“Assertion ‘__builtin_expect(__n size(), true)’ failed” error in Visual Studio Code Python

I know there is already a lot on Assertion Failure. But none was useful for me. Hear me out.

This is the code:

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

### random data frame with an obvious outlier
nrows = 100
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

This is the error:

/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)

The error happens at line:

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

Python version:

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

Code works fine in Google Colab. So why is it happening only in the IDE? And if it’s a setting or environment issue then what can I do? This is my first time working on Visual Studio Code.

Thank you


Author of the library here. There was a bug in the code which would only trigger when the setup has defined a macro _GLIBCXX_ASSERTIONS and would otherwise not show up. It should be fixed now in the latest version (1.7.0) – please try again (pip install -U outliertree) and comment in the github issue tracker if the problem persists.