You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The result series has a duplicate index column 'ticker' as in ["ticker, "ticker", "date"]
Expected Behavior
Some calculations like shift, pct_change, etc can be applied to a series groupby and they will not change the resulting index. This makes sense because these functions are "one-to-one", they keep the series index intact. However other calculations like rolling, ewm, expanding which are also one-to-one, introduce a duplicate index when applied to a groupby.
As a side note, this problem is already addressed for the apply method with the group_keys=False option. There is also an as_index=False option at the DataFrame level that seems to fix the problem, but it is available only at DataFrame level.
It would make sense that rolling, ewm, expanding behave the same way as shift, pct_change, etc. Short of changing the behavior there should be an option like as_index=False or group_keys=False to fix the duplicate index when working with series.
Thanks
Installed Versions
INSTALLED VERSIONS
commit : bdc79c1
python : 3.9.18.final.0
python-bits : 64
OS : Darwin
OS-release : 23.3.0
Version : Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:00 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
I agree that #51751 seems to be pointing to the same issue! rolling should be a transform in the same way that shift, pct_change are. The second issue #36507 is only a partial work around because from my experience using as_index=False does not add group keys to the index but it still adds them as data columns. If there had to be a work around, I would say the most logical would be to extend group_keys=False to rolling etc ...
group_keys was added specifically to give users some flexibility with apply. I would be very hesitant to expanding it to other methods, especially because it is very similar to as_index.
Pandas version checks
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 main branch of pandas.
Reproducible Example
Issue Description
The result series has a duplicate index column 'ticker' as in ["ticker, "ticker", "date"]
Expected Behavior
Some calculations like
shift
,pct_change
, etc can be applied to a series groupby and they will not change the resulting index. This makes sense because these functions are "one-to-one", they keep the series index intact. However other calculations likerolling
,ewm
,expanding
which are also one-to-one, introduce a duplicate index when applied to a groupby.As a side note, this problem is already addressed for the
apply
method with thegroup_keys=False
option. There is also anas_index=False
option at the DataFrame level that seems to fix the problem, but it is available only at DataFrame level.It would make sense that
rolling
,ewm
,expanding
behave the same way asshift
,pct_change
, etc. Short of changing the behavior there should be an option likeas_index=False
orgroup_keys=False
to fix the duplicate index when working with series.Thanks
Installed Versions
INSTALLED VERSIONS
commit : bdc79c1
python : 3.9.18.final.0
python-bits : 64
OS : Darwin
OS-release : 23.3.0
Version : Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:00 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.1
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 24.0
Cython : None
pytest : 8.0.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.1.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.18.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.3
numba : 0.59.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.12.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: