Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use .ix in IntervaIndex('pandas._libs.interval.IntervalTree' object has no attribute 'get_value') #27865

Janhonho opened this issue Aug 12, 2019 · 3 comments


Copy link

@Janhonho Janhonho commented Aug 12, 2019

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\", line 2961, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-12-1ae8ba69565c>", line 1, in <module>
  File "D:\PyTest\venv\lib\site-packages\pandas\core\", line 125, in __getitem__
    values = self.obj._get_value(*key)
  File "D:\PyTest\venv\lib\site-packages\pandas\core\", 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]

Copy link

@Janhonho Janhonho commented Aug 12, 2019

In fact I've got another problem beside, I cannot use:
init_cut = init_cut.astype(pd.Interval)
I've got another error:
Traceback (most recent call last):
File "D:\anaconda\lib\site-packages\IPython\core\", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
File "D:\PyTest\venv\lib\site-packages\pandas\core\", line 5883, in astype
dtype=dtype, copy=copy, errors=errors, **kwargs
File "D:\PyTest\venv\lib\site-packages\pandas\core\internals\", line 581, in astype
return self.apply("astype", dtype=dtype, **kwargs)
File "D:\PyTest\venv\lib\site-packages\pandas\core\internals\", line 438, in apply
applied = getattr(b, f)(**kwargs)
File "D:\PyTest\venv\lib\site-packages\pandas\core\internals\", line 557, in astype
return self._astype(dtype, copy=copy, errors=errors, values=values, **kwargs)
File "D:\PyTest\venv\lib\site-packages\pandas\core\internals\", line 612, in _astype
dtype = pandas_dtype(dtype)
File "D:\PyTest\venv\lib\site-packages\pandas\core\dtypes\", line 2067, in pandas_dtype
raise TypeError("dtype '{}' not understood".format(dtype))
TypeError: dtype '<class 'pandas._libs.interval.Interval'>' not understood

which is ok in version 0.23.4
but error in version 0.24.x and later version


Copy link

@Janhonho Janhonho commented Aug 15, 2019

Any can help me....


Copy link

@jorisvandenbossche jorisvandenbossche commented Aug 15, 2019

@Janhonho for the first bug, there is a PR to fix this in 0.25.1: #27926. However, note that you are using ix which is deprecated and will be removed in the next major version. So in this case you can actually rather do bin_df.iloc[0:2,0].

For the second one (init_cut.astype(pd.Interval)), that only worked by accident, where pd.Interval (which is not a data type object, but the scalar interval class) was interpreted as general 'object' dtype. So to have the same as you had before, you can now do init_cut.astype(object) instead. But note that this does not convert to an actual interval type.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants