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: Series(range(...)) fails when range contains values not supported by int64 #30173

Closed
jschendel opened this issue Dec 10, 2019 · 1 comment · Fixed by #41579
Closed

BUG: Series(range(...)) fails when range contains values not supported by int64 #30173

jschendel opened this issue Dec 10, 2019 · 1 comment · Fixed by #41579
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Numeric Operations Arithmetic, Comparison, and Logical operations Series Series data structure
Milestone

Comments

@jschendel
Copy link
Member

Code Sample, a copy-pastable example if possible

The following fails on master:

In [1]: import pandas as pd; pd.__version__
Out[1]: '0.26.0.dev0+1255.gb9f26e21e'

In [2]: pd.Series(range(2**63, 2**63 + 4))
---------------------------------------------------------------------------
OverflowError: Python int too large to convert to C long

In [3]: pd.Series(range(2**73, 2**73 + 4))
---------------------------------------------------------------------------
OverflowError: Python int too large to convert to C long

But is successful when doing an intermediate conversion to list:

In [4]: pd.Series(list(range(2**63, 2**63 + 4)))
Out[4]: 
0    9223372036854775808
1    9223372036854775809
2    9223372036854775810
3    9223372036854775811
dtype: uint64

In [5]: pd.Series(list(range(2**73, 2**73 + 4)))
Out[5]: 
0    9444732965739290427392
1    9444732965739290427393
2    9444732965739290427394
3    9444732965739290427395
dtype: object

Problem description

Series(range(...)) fails when values in the range are not supported by int64, but construction is successful for an equivalent list.

Expected Output

I'd expect In [2]/In [3] to be successful and produce output equivalent to Out[4]/Out[5].

Output of pd.show_versions()

INSTALLED VERSIONS

commit : b9f26e2
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 18.6.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.26.0.dev0+1255.gb9f26e21e
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 19.1.1
setuptools : 41.6.0.post20191030
Cython : 0.29.13
pytest : 4.6.2
hypothesis : 4.23.6
sphinx : 1.8.5
blosc : None
feather : None
xlsxwriter : 1.1.8
lxml.etree : 4.3.3
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.5.0
pandas_datareader: None
bs4 : 4.7.1
bottleneck : 1.2.1
fastparquet : 0.3.0
gcsfs : None
lxml.etree : 4.3.3
matplotlib : 3.1.0
numexpr : 2.6.9
odfpy : None
openpyxl : 2.6.2
pandas_gbq : None
pyarrow : 0.11.1
pytables : None
pytest : 4.6.2
s3fs : 0.2.1
scipy : 1.2.1
sqlalchemy : 1.3.4
tables : 3.5.2
xarray : 0.12.1
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.8

@jschendel jschendel added Bug Numeric Operations Arithmetic, Comparison, and Logical operations Series Series data structure Constructors Series/DataFrame/Index/pd.array Constructors labels Dec 10, 2019
@jschendel jschendel added this to the Contributions Welcome milestone Dec 10, 2019
@topper-123
Copy link
Contributor

This is indeed a bit of an edge case.

Could #30171 be accepted and this issue be expanded to cover dataframes also? This issue and the problem after #30171 is merged are exactly the same, as in both cases pandas does a simple np.arange(..., dtype="int64") in order to convert a range to an array, where (to match the list behaviour), it needs to be a bit more sofisticated.

Probably there should be a range_to_array function, that should be common for data frames and series constructors.

@jreback jreback modified the milestones: Contributions Welcome, 1.3 May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Numeric Operations Arithmetic, Comparison, and Logical operations Series Series data structure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants