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
When performing a groupby.rolling using a level parameter, an additional level(s) are inserted into the MultiIndex. The result is an index incompatible with original frame (raises: AssertionError: Length of new_levels (3) must be <= self.nlevels (2))
Expected Behavior
Groupby(level=n).rolling should return compatible MultiIndex for assignment to derived DataFrame, to allow ergonomics such as:
Totally possible there is a specific difference in grouping by named columns versus using level param that I do not understand; but I have always understood them to have been syntactic sugar for functionally equivalent operations. Happy to submit a documentation update PR if this is my misunderstanding. 🙏
Installed Versions
INSTALLED VERSIONS
------------------
commit : d9cdd2ee5a58015ef6f4d15c7226110c9aab8140
python : 3.11.8.final.0
python-bits : 64
OS : Darwin
OS-release : 23.1.0
Version : Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 2.2.2
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.1
Cython : None
pytest : 7.4.0
hypothesis : None
...
zstandard : 0.19.0
tzdata : 2023.3
qtpy : 2.4.1
pyqt5 : None
The text was updated successfully, but these errors were encountered:
drmarshall
changed the title
BUG: GroupByRolling creates additional MultiIndex level which prevents assignment on parent
BUG: GroupByRolling duplicates MultiIndex levels, which prevents assignment on parent
Apr 26, 2024
Thanks for the report! I think this is a duplicate of #51751, which generally speaking, is a discussion on how to treat the index on a rolling operation. Can you take a look at that issue and provide any feedback there?
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
When performing a groupby.rolling using a level parameter, an additional level(s) are inserted into the MultiIndex. The result is an index incompatible with original frame (raises:
AssertionError: Length of new_levels (3) must be <= self.nlevels (2)
)Expected Behavior
Groupby(level=n).rolling
should return compatibleMultiIndex
for assignment to derived DataFrame, to allow ergonomics such as:This behavior should be roughly the same as grouping by column(s) string names:
Totally possible there is a specific difference in grouping by named columns versus using
level
param that I do not understand; but I have always understood them to have been syntactic sugar for functionally equivalent operations. Happy to submit a documentation update PR if this is my misunderstanding. 🙏Installed Versions
The text was updated successfully, but these errors were encountered: