Skip to content

BUG: cumsum() shows inconsistent results in nullable dtype #39479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
koizumihiroo opened this issue Jan 30, 2021 · 1 comment
Closed
2 of 3 tasks

BUG: cumsum() shows inconsistent results in nullable dtype #39479

koizumihiroo opened this issue Jan 30, 2021 · 1 comment
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays

Comments

@koizumihiroo
Copy link

koizumihiroo commented Jan 30, 2021

  • 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

# import pandas as pd
# import numpy as np

# like https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.cumsum.html
# Ex1
>>> pd.Series([2, np.nan, 5, -1, 0], dtype="float").cumsum()
0    2.0
1    NaN
2    7.0
3    6.0
4    6.0
dtype: float64

# Ex2
>>> pd.Series([2, np.nan, 5, -1, 0], dtype="Float64").cumsum()
0    2.0
1    2.0
2    7.0
3    6.0
4    6.0
dtype: object

# Ex3
>>> pd.Series([2, np.nan, 5, -1, 0], dtype="Int64").cumsum()
0       2
1    <NA>
2    <NA>
3    <NA>
4    <NA>
dtype: object

Problem description

  • Ex1 is expected behavior while Ex2 and Ex3 yield different values.
  • Ex2 returns dtype: object but Float64 is expected, the same applies to Ex3.
  • Other cum-family methods (cumprod, cummax, cummin) have the same problem.

Expected Output

# Ex2
>>> pd.Series([2, np.nan, 5, -1, 0], dtype="Float64").cumsum()
0    2.0
1    <NA>
2    7.0
3    6.0
4    6.0
dtype: Float64

# Ex3
>>> pd.Series([2, np.nan, 5, -1, 0], dtype="Int64").cumsum()
0       2
1    <NA>
2       7
3       6
4       6
dtype: Int64

Environment

FROM python:3.9.1-slim-buster
WORKDIR /home
RUN pip install pandas==1.2.1
CMD ["/usr/local/bin/python"]

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 9d598a5
python : 3.9.1.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.121-linuxkit
Version : #1 SMP Tue Dec 1 17:50:32 UTC 2020
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.1
numpy : 1.19.5
pytz : 2020.5
dateutil : 2.8.1
pip : 21.0
setuptools : 52.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@koizumihiroo koizumihiroo added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 30, 2021
@jorisvandenbossche jorisvandenbossche added NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 3, 2021
@phofl
Copy link
Member

phofl commented Dec 17, 2022

This was fixed recently

@phofl phofl closed this as completed Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants