Skip to content

groupby indexing is giving the wrong index #28652

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
landmann opened this issue Sep 27, 2019 · 0 comments · Fixed by #28662
Closed

groupby indexing is giving the wrong index #28652

landmann opened this issue Sep 27, 2019 · 0 comments · Fixed by #28662
Labels
Bug Groupby Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@landmann
Copy link

landmann commented Sep 27, 2019

Code Sample, a copy-pastable example if possible

a = pd.DataFrame([range(3)]*3,index=map(str, range(3))).T
a.iloc[:,0] = [10, 11, 11]

a.groupby('0').apply(lambda x: print(x.index))

indexes = a.groupby('0').apply(lambda x: x.index)
print(indexes)

index_lengths = a.groupby('0').apply(lambda x: len(x.index))
print(index_lengths)

indexes_lengths = a.groupby('0').apply(lambda x: x.index).apply(len)
print(indexes_lengths)

assert indexes_lengths.equals(index_lengths), "Apply indexes are returning the wrong index"

Problem description

Groupby indexing is returning the wrong value. It is returning the indexes of the last group for all the groups.

Expected Output

0
10    Int64Index([0], dtype='int64')
11    Int64Index([1, 2], dtype='int64')

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.8.final.0
python-bits : 64
OS : Linux
OS-release : 5.2.0-arch2-1-ARCH
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C
LOCALE : None.None

pandas : 0.25.1
numpy : 1.15.4
pytz : 2019.1
dateutil : 2.8.0
pip : 19.1.1
setuptools : 41.0.1
Cython : 0.28.5
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : 0.4.0
xlsxwriter : None
lxml.etree : 4.3.4
html5lib : None
pymysql : None
psycopg2 : 2.8.3 (dt dec pq3 ext lo64)
jinja2 : 2.10.1
IPython : 7.5.0
pandas_datareader: None
bs4 : None
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.3.4
matplotlib : 2.2.2
numexpr : 2.6.9
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
s3fs : 0.1.5
scipy : 1.3.1
sqlalchemy : None
tables : 3.4.4
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None

@dsaxton dsaxton mentioned this issue Sep 27, 2019
5 tasks
@gfyoung gfyoung added Bug Groupby Indexing Related to indexing on series/frames, not to indexes themselves labels Sep 28, 2019
@jreback jreback added this to the 1.0 milestone Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants