Skip to content

Using loc[] or at[] to add rows doesn't work with an IntervalIndex doesn't work #35422

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

Closed
konstantinmiller opened this issue Jul 27, 2020 · 2 comments
Labels
Bug Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Interval Interval data type Needs Info Clarification about behavior needed to assess issue

Comments

@konstantinmiller
Copy link

It seems that a data frame with an IntervalIndex won't let you use loc[] or at[] to add rows.

I would expect the following to work:

df = pd.DataFrame(index=pd.IntervalIndex(closed='left', dtype='interval[int64]',
                                         data=[pd.Interval(0, 1, closed='left')]),
                  data={'a': [42]})
df.at[pd.Interval(2, 3, closed='left'), 'a'] = 43

However, it throws a confusing error

AttributeError: 'pandas._libs.interval.IntervalTree' object has no attribute 'set_value'
@konstantinmiller konstantinmiller added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 27, 2020
@simonjayhawkins
Copy link
Member

@konstantinmiller Thanks for the report.

using loc appears to be appending a row. (on master and 0.25.3)

>>> pd.__version__
'1.1.0rc0+7.g04e9e0afd'
>>>
>>> df = pd.DataFrame(
...     index=pd.IntervalIndex(
...         closed="left", dtype="interval[int64]", data=[pd.Interval(0, 1, closed="left")]
...     ),
...     data={"a": [42]},
... )
>>> df
         a
[0, 1)  42
>>>
>>> df.loc[pd.Interval(2, 3, closed="left"), "a"] = 43
>>> df
           a
[0, 1)  42.0
[2, 3)  43.0
>>>

can you give an example or versions where loc is failing.

@simonjayhawkins simonjayhawkins added Indexing Related to indexing on series/frames, not to indexes themselves Interval Interval data type Needs Info Clarification about behavior needed to assess issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 27, 2020
@simonjayhawkins
Copy link
Member

The at issue is for getting values and not just setting values. This is covered by #27927 so closing as duplicate.

@simonjayhawkins simonjayhawkins added the Duplicate Report Duplicate issue or pull request label Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Interval Interval data type Needs Info Clarification about behavior needed to assess issue
Projects
None yet
Development

No branches or pull requests

2 participants