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
# [2] Out: # original index [0,1,2,3,4] is in outputtimestampyida02021-09-0100:00:001.012021-09-0101:00:001.0b22021-09-0102:00:001.032021-09-0103:00:001.042021-09-0104:00:001.0
# [3] In:grp["y"].count()
# [3] Out:# original index [0,1,2,3,4] is missing in output as opposed to [2] Outidtimestampa2021-09-0100:00:001.02021-09-0101:00:001.0b2021-09-0102:00:001.02021-09-0103:00:001.02021-09-0104:00:001.0Name: y, dtype: float64
# [4] In:grp.count() # same as [2] In
# [4] Out:# output is inconsistent with that from [2] Outtimestampyidtimestampa2021-09-0100:00:00NaT1.02021-09-0101:00:00NaT1.0b2021-09-0102:00:00NaT1.02021-09-0103:00:00NaT1.02021-09-0104:00:00NaT1.0
Expected Output
[4] Out should be identical to [2] Out
I as a user would hope original index is, at least optionally if not by default, kept in output so I can efficiently join the rolling count results back to the original df.
Problem description
Groupby rolling count gives inconsistent outputs (see [2] Out and [4] Out) when running cell 1~4. Same problem exists when count is replaced by agg(len)
[3] Out using pandas 1.3.2 ignored original index whereas [2] Out (as well as [3] Out using pandas 1.1.5 ) maintained original index. Original index (in this example, [0,1,2,3,4]) should ideally be optionally kept in outputs otherwise there will be no way to traceback which rolling count corresponds to the original row (see [3] Out). Joining two data frames on ['id', 'timestamp'] afterwards is not the correct solution as it is easy to find non 1-1 match examples.
# [3] Out: pandas 1.3.2# original index [0,1,2,3,4] is missing. idtimestampa2021-09-0100:00:001.02021-09-0101:00:001.0b2021-09-0102:00:001.02021-09-0103:00:001.02021-09-0104:00:001.0Name: y, dtype: float64
# [3] Out: pandas 1.1.5# original index [0,1,2,3,4] maintained as expected though the rolling count numbers are wrong (should be [1,1,1,1,1])ida01.012.0b21.032.043.0
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit : 5f648bf
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.14.225-121.362.amzn1.x86_64
Version : #1 SMP Tue Mar 23 00:29:14 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
[3] Out may actually be correct and [2] Out index might have the bug because according to on documentation
For a DataFrame, a datetime-like column or Index level on which to calculate the rolling window, rather than the DataFrame’s index. Provided integer column is ignored and excluded from result since an integer index is not used to calculate the rolling window.
So the original integer index in df should be ignored since on was specified.
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.
Code Sample, a copy-pastable example
Expected Output
[4] Out
should be identical to[2] Out
df
.Problem description
[2] Out
and[4] Out
) when running cell 1~4. Same problem exists whencount
is replaced byagg(len)
[3] Out
using pandas 1.3.2 ignored original index whereas[2] Out
(as well as[3] Out
using pandas 1.1.5 ) maintained original index. Original index (in this example,[0,1,2,3,4]
) should ideally be optionally kept in outputs otherwise there will be no way to traceback which rolling count corresponds to the original row (see[3] Out
). Joining two data frames on['id', 'timestamp']
afterwards is not the correct solution as it is easy to find non 1-1 match examples.Output of
pd.show_versions()
pandas : 1.3.2
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 57.4.0
Cython : None
pytest : None
hypothesis : None
sphinx : 4.1.2
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.26.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.07.0
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : 0.4.2
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: