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
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
To reproduce:
importpandasaspd# Create a DF with a group column and more than 1 group (10 rows toy data)dfBug=pd.DataFrame(data={
'Date': pd.date_range('2020-01-01', '2020-01-10'),
'gb': ['group_1'] *6+ ['group_2'] *4,
'value': range(10),
})
center=True# Problem only occurs when center=True# the apply produces the expected resultvia_apply=dfBug.groupby('gb').apply(lambdadf: \
df.set_index('Date').rolling(6, center=center, min_periods=1).value.mean())
# the groupby.rolling... produces a different resultvia_groupbyrolling=dfBug.groupby('gb') \
.rolling(6, on='Date', center=center, min_periods=1).value.mean()
print(pd.concat([via_apply.rename('apply'),
via_groupbyrolling.rename('groupbyrolling'),
(via_apply==via_groupbyrolling).rename('is-equal'),
], axis=1))
assert (abs(via_apply-via_groupbyrolling) <1e-4).all()
Problem description
The code via apply and via groupbyrolling should produce identical results, yet the groupbyrolling version seems to ignore the grouping for the mean. Strange enough, when setting center to False, both variants produce identical results.
Output is the following (I expect the is-equal column to be True in all rows):
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
To reproduce:
Problem description
The code via apply and via groupbyrolling should produce identical results, yet the groupbyrolling version seems to ignore the grouping for the mean. Strange enough, when setting center to False, both variants produce identical results.
Output is the following (I expect the is-equal column to be True in all rows):
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : db08276
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-51-generic
Version : #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8
pandas : 1.1.3
numpy : 1.17.4
pytz : 2020.1
dateutil : 2.7.3
pip : 20.0.2
setuptools : 45.2.0
Cython : 0.29.21
pytest : 4.6.9
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.3.3
lxml.etree : 4.5.0
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.13.0
pandas_datareader: None
bs4 : 4.8.2
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.1
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.1.0
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: