Skip to content

BUG: DataFrame size overflows on Windows #34557

Open
@FHTMitchell

Description

@FHTMitchell
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions