Cannot use .ix in IntervaIndex('pandas._libs.interval.IntervalTree' object has no attribute 'get_value') · Issue #27865 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

x = pd.Series([-2.801298, -2.882724, -3.007899, -2.704554, -3.398761, -2.805034, -2.87554, -2.805034, -2.886459, -2.471618]) y= pd.Series([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) init_cut = pd.qcut(x, 5, duplicates='drop') retbin = pd.Series(init_cut.values.categories).sort_values() retbin.iloc[0] = pd.Interval(-np.inf, retbin.iloc[0].right) retbin.iloc[-1] = pd.Interval(retbin.iloc[-1].left, np.inf) init_cut = pd.cut(x, pd.IntervalIndex(retbin)) init_cut = init_cut.astype(object) bin_df = pd.crosstab(index=init_cut, columns=y) bin_df = bin_df.reindex(retbin) bin_df = bin_df.sort_index() bin_df = bin_df.fillna(0.0) bin_df['nbin'] = np.nan

Problem description

bin_df =
col_0 0 nbin
(-inf, -2.911] 2 NaN
(-2.911, -2.878] 2 NaN
(-2.878, -2.805] 3 NaN
(-2.805, -2.782] 1 NaN
(-2.782, inf] 2 NaN

if I use bin_df.ix[0:2,0], I got an error like:

Traceback (most recent call last): File "D:\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2961, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in bin_df.ix[0:1,'nbin'] File "D:\PyTest\venv\lib\site-packages\pandas\core\indexing.py", line 125, in getitem values = self.obj._get_value(*key) File "D:\PyTest\venv\lib\site-packages\pandas\core\frame.py", line 2827, in _get_value return engine.get_value(series._values, index) AttributeError: 'pandas._libs.interval.IntervalTree' object has no attribute 'get_value'

the version is 0.25.0
but it works well in 0.24.x

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]