BUG: RollingGroupby duplicates columns in index even with group_keys=False · Issue #37641 · pandas-dev/pandas (original) (raw)


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd

arrays = [['val1', 'val1', 'val2'], ['val1', 'val1', 'val2']] index = pd.MultiIndex.from_arrays(arrays, names=('idx1', 'idx2'))

s = pd.Series([1, 2, 3], index=index) print( s.groupby(["idx1", "idx2"], group_keys=False).rolling(1).mean() )

Problem description

the group_keys parameter in Seried.groupby() is broken since 1.1.0 when using .rolling()

It does not seem to be an issue if another function instead of rolling is used, eg

s.groupby(["idx1", "idx2"], group_keys=False).mean()

In pandas=1.1.{0,1} the output is

idx1 idx2  
val1 val1  (val1, val1)   1.0
     val1  (val1, val1)   2.0
val2 val2  (val2, val1)   3.0

In pandas=1.1.{2,3,4} the output is

idx1 idx2  idx1 idx2     
val1 val1  val1 val1   1.0
                val1   2.0
val2 val2  val2 val2   3.0

Expected Output (as per pandas 1.0.*)

idx1 idx2       
val1 val1   1.0
     val1   2.0
val2 val2   3.0

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2ca0a2
python : 3.6.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.17134
machine : AMD64
processor : Intel64 Family 6 Model 63 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.1.1
numpy : 1.16.1
pytz : 2018.9
dateutil : 2.8.0
pip : 10.0.1
setuptools : 39.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.3.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10
IPython : 7.2.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 2.6.0
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None