Skip to content

bug: inconsistent Series indexing crash, depending on DataFrame index type?? #32263

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
xuancong84 opened this issue Feb 26, 2020 · 1 comment
Closed

Comments

@xuancong84
Copy link

Recently, I encountered a very strange bug when indexing pd.Series in Pandas groupby object.

if False:
	df = pd.DataFrame({'app':['a', 'b', 'c', 'd', 'e'], 'sessionId':['1', '1', '2', '3', '3']},
		index=['a1', 'a2', 'a3', 'a4', 'a5']) # this will not cause the last line to crash
else:
	df = pd.DataFrame({'app': ['a', 'b', 'c', 'd', 'e'], 'sessionId': ['1', '1', '2', '3', '3']},
		index=[1,2,3,4,5]) # this will cause the last line to crash

df1 = [v.app[0] for k, v in df.groupby('sessionId')] # the crashing line

As shown in the above code, if df.index elements are string, pd.Timestamp, etc., the last line will not crash; however, if df.index elements are int, float, etc., the last line will crash. Ridiculously, in both cases type(v.app) is pd.Series, yet one is index-able, while the other one is not. It is worth noting that the crashing line has not even touched df.index, so why does the value type of df.index elements matters?

So do we have another general inconsistency due to incompetent programming?

@MarcoGorelli
Copy link
Member

0 will be interpreted as a label for integer indexes, rather than as a position.

If you need to access the position 0, use .iloc[0], as advised in the user guide

So do we have another general inconsistency due to incompetent programming?

Please try to be constructive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants