Skip to content
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

BUG: DataFrame size overflows on Windows #34557

Open
2 of 3 tasks
FHTMitchell opened this issue Jun 3, 2020 · 5 comments
Open
2 of 3 tasks

BUG: DataFrame size overflows on Windows #34557

FHTMitchell opened this issue Jun 3, 2020 · 5 comments
Labels
Bug Windows Windows OS

Comments

@FHTMitchell
Copy link

FHTMitchell commented Jun 3, 2020

  • 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

a = np.ones(2**30 + 1, dtype=np.int8)
df = pd.DataFrame.from_dict({'a': a, 'b': a})
print(df.size)  # --> -2147483646
print(df.sum(axis=0))  # --> 
# a   NaN
# b   NaN
# dtype: float64

Problem description

On windows, dataframes with more than 2^31 elements (max 32 bit int) result in negative sizes and nan results from operations performed on them.

This problem only seems to exist on windows (64-bit Windows-10-10.0.18362-SP0). This seems to be from the assumption that np.prod(self.shape) will not overflow, but numpy makes no such guarantee.

Expected Output

positive size, non-nan sum

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.1.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 7, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.0.1
numpy : 1.16.4
pytz : 2018.9
dateutil : 2.8.0
pip : 19.2.2
setuptools : 41.0.1
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 : 7.8.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@FHTMitchell FHTMitchell added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 3, 2020
@TomAugspurger TomAugspurger removed the Needs Triage Issue that has not been reviewed by a pandas team member label Sep 4, 2020
@TomAugspurger
Copy link
Contributor

Thanks for the report. Are you interested in working on this?

What's your expected output for the sum? Would it be equivalent to this on a 64-bit system?

In [19]: pd.DataFrame({"A": np.array([np.iinfo('int64').max] * 2)}).sum()
Out[19]:
A   -2
dtype: int64

@TomAugspurger TomAugspurger added the Windows Windows OS label Sep 4, 2020
@FHTMitchell
Copy link
Author

Hi @TomAugspurger

I would be happy to try and fix. Your snippet, however, doesn't represent the problem. It's about the size of the array, not the contents. The expected output would be (running my original code on redhat linux 64bit):

import pandas as pd
import numpy as np

a = np.ones(2**30 + 1, dtype=np.int8)
df = pd.DataFrame.from_dict({'a': a, 'b': a})
print(df.size)  # --> 2147483650
print(df.sum(axis=0))  # --> 
# a    1073741825
# b    1073741825
# dtype: int64

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Sep 4, 2020

Agreed that my example doesn't demonstrate the .size issue, which is a bug. I was demonstrating the output of DataFrame.sum(), where we have an established behavior of wrapping around for int64 dtype. Or do I misunderstand still

@FHTMitchell
Copy link
Author

FHTMitchell commented Sep 4, 2020

I see. I'd expect the result of sum to either autocast to a larger int size (as happens on linux) or to wrap. What I would not expect is for the sum to be cast to a float type and then return NaN. Note that my original example is on a 64 bit system.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Sep 4, 2020

The size issue is coming up in #35227 too.[

Will leave this open for the overflow issue.

Note that my original example is on a 64 bit system

I think that's the part that we need to clarify. We should (I think) have consistent behavior across windows / linux. We might have different behavior between 32 and 64-bit systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Windows Windows OS
Projects
None yet
Development

No branches or pull requests

2 participants