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

BUG: df.groupby.apply(lambda x: x.reindex) behaviour changed from Pandas 1.3.0 to 1.3.3 #43727

Closed
2 of 3 tasks
mlee94 opened this issue Sep 24, 2021 · 1 comment
Closed
2 of 3 tasks
Labels
Bug Duplicate Report Duplicate issue or pull request Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@mlee94
Copy link

mlee94 commented Sep 24, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

start_date = pd.to_datetime('2019-01-01')
end_date = pd.to_datetime('2019-01-05')
data = {
    'code': ['X333']*5,
    'date': pd.date_range(start_date, periods=5),
    'float': np.random.randn(5),
}

df = (
    pd.DataFrame(data)
    .set_index('date')
    .groupby('code')
    .apply(
        lambda x: x.reindex(pd.date_range(start_date, end_date, name='date'))
    )
)
print(df)

Issue Description

pandas=1.3.3
Group by key code is removed from the multi-index:

            code     float
date
2019-01-01  X333 -0.732025
2019-01-02  X333  0.251650
2019-01-03  X333  0.301808
2019-01-04  X333 -0.585017
2019-01-05  X333  0.067119

Expected Behavior

pandas=1.3.0
Group by key code is kept in the multi-index:

                 code     float
code date
X333 2019-01-01  X333 -0.971248
     2019-01-02  X333  0.701875
     2019-01-03  X333  1.222485
     2019-01-04  X333  0.315564
     2019-01-05  X333  0.836289

Installed Versions


INSTALLED VERSIONS

commit : 73c6825
python : 3.7.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 58 Stepping 0, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.3.3
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : 2.9.1 (dt dec pq3 ext lo64)
jinja2 : 2.11.3
IPython : 7.27.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fsspec : 2021.08.1
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.4.24
tables : None
tabulate : None
xarray : 0.19.0
xlrd : None
xlwt : None
numba : 0.53.0

@mlee94 mlee94 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 24, 2021
@TomAugspurger
Copy link
Contributor

I think this is the same as #43568.

@TomAugspurger TomAugspurger added the Duplicate Report Duplicate issue or pull request label Sep 24, 2021
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 Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants