Skip to content

BUG: Bug in .loc performing fallback integer indexing with object dtype indices (GH7496) #7497

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

Merged
merged 1 commit into from
Jun 19, 2014

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Jun 18, 2014

closes #7496



In [4]: s = Series()

In [5]: s.loc[1] = 1

In [6]: s.loc['a'] = 2

In [7]: s.loc[-1]
KeyError: 'the label [-1] is not in the [index]'

In [8]: s.loc[[-1, -2]]
Out[8]: 
-1   NaN
-2   NaN
dtype: float64

In [9]: s.loc[['4']]
Out[9]: 
4   NaN
dtype: float64

In [10]: s.loc[-1] = 3

In [11]: s.loc[[-1,-2]]
Out[11]: 
-1     3
-2   NaN
dtype: float64

In [12]: s['a'] = 2

In [13]: s.loc[[-2]]
Out[13]: 
-2   NaN
dtype: float64

In [14]: del s['a']

In [15]: s.loc[[-2]] = 0
KeyError: '[-2] not in index'

@code-of-kpp
Copy link

s.loc[[-2]] = 0

shouldn't -2 to be added to index after that?

@code-of-kpp
Copy link

this one looks similar #5420

@jreback
Copy link
Contributor Author

jreback commented Jun 18, 2014

for the s.loc[[-2]] = 0.

Setting with a single indexer (e.g. s.loc[-2] = 0 is fine as this is enlargement.
However, setting with a list (either on a Series or a DataFrame) was deemed to be
more 'error prone', so it was disallowed.

e.g. both s.loc[[-2]] = 0 and df.loc[[-2]] = 0 are not allowed unless the location already exists.
though s.loc[-2] = 0 and df.loc[-2] = 0 will work

jreback added a commit that referenced this pull request Jun 19, 2014
BUG: Bug in .loc performing fallback integer indexing with object dtype indices (GH7496)
@jreback jreback merged commit d0fa20a into pandas-dev:master Jun 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: strange behavior of .loc indexer: falling back to integer-based indexing with list
2 participants