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 constructor with nullable unsigned integer dtype fails with large number #38798

Closed
arw2019 opened this issue Dec 30, 2020 · 5 comments · Fixed by #50757
Closed

BUG: Series constructor with nullable unsigned integer dtype fails with large number #38798

arw2019 opened this issue Dec 30, 2020 · 5 comments · Fixed by #50757
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors NA - MaskedArrays Related to pd.NA and nullable extension arrays

Comments

@arw2019
Copy link
Member

arw2019 commented Dec 30, 2020

xref #38746

The following runs fine:

In [30]: s = pd.Series([np.iinfo(np.uint64).max-1, 1], dtype="uint64")

In [31]: s
Out[31]: 
0    18446744073709551614
1                       1
dtype: uint64

but with the equivalent extension dtype the constructor throws:

In [29]: s = pd.Series([np.iinfo(np.uint64).max-1, 1], dtype="UInt64")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/repos/pandas/pandas/core/arrays/integer.py in safe_cast(values, dtype, copy)
    100     try:
--> 101         return values.astype(dtype, casting="safe", copy=copy)
    102     except TypeError as err:

TypeError: Cannot cast array data from dtype('float64') to dtype('uint64') according to the rule 'safe'

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
<ipython-input-29-7fde9ec5cff9> in <module>
----> 1 s = pd.Series([np.iinfo(np.uint64).max-1, 1], dtype="UInt64")

~/repos/pandas/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    339                     data = data.copy()
    340             else:
--> 341                 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
    342 
    343                 data = SingleBlockManager.from_array(data, index)

~/repos/pandas/pandas/core/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
    485 
    486         if dtype is not None:
--> 487             subarr = _try_cast(data, dtype, copy, raise_cast_failure)
    488         else:
    489             subarr = maybe_convert_platform(data)

~/repos/pandas/pandas/core/construction.py in _try_cast(arr, dtype, copy, raise_cast_failure)
    863         # SparseDtype does not
    595         array_type = dtype.construct_array_type()._from_sequence
--> 596         subarr = array_type(arr, dtype=dtype, copy=copy)
    597         return subarr
    598 

~/repos/pandas/pandas/core/arrays/integer.py in _from_sequence(cls, scalars, dtype, copy)
    307         cls, scalars, *, dtype=None, copy: bool = False
    308     ) -> "IntegerArray":
--> 309         values, mask = coerce_to_array(scalars, dtype=dtype, copy=copy)
    310         return IntegerArray(values, mask)
    311 

~/repos/pandas/pandas/core/arrays/integer.py in coerce_to_array(values, dtype, mask, copy)
    204         values = safe_cast(values, dtype, copy=False)
    205     else:
--> 206         values = safe_cast(values, dtype, copy=False)
    207 
    208     return values, mask

~/repos/pandas/pandas/core/arrays/integer.py in safe_cast(values, dtype, copy)
    106             return casted
    107 
--> 108         raise TypeError(
    109             f"cannot safely cast non-equivalent {values.dtype} to {np.dtype(dtype)}"
    110         ) from err

TypeError: cannot safely cast non-equivalent float64 to uint64
@arw2019 arw2019 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 30, 2020
@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 Dec 30, 2020
@jorisvandenbossche
Copy link
Member

This is related to #30268, in the sense that it has the same cause: we let numpy do the inference on the list of values first, and in this case of large integers, numpy apparently converts it to a float array (loosing precision) instead of a uint64 array.
So I think the solution will probably be similar. There was a PR #30282, but was blocked by other issues.

@arw2019
Copy link
Member Author

arw2019 commented Dec 30, 2020

This is related to #30268, in the sense that it has the same cause: we let numpy do the inference on the list of values first, and in this case of large integers, numpy apparently converts it to a float array (loosing precision) instead of a uint64 array.

So I think the solution will probably be similar. There was a PR #30282, but was blocked by other issues.

Thanks for linking these! I'll look into resuscitating 30282, probably by resolving the blocker first

@jorisvandenbossche
Copy link
Member

I need to look back at the original PR, but I think the blocker is at the moment mainly #38315

@arw2019
Copy link
Member Author

arw2019 commented Dec 30, 2020

I need to look back at the original PR, but I think the blocker is at the moment mainly #38315

I think that's right

@fangchenli
Copy link
Member

This test has passed on arm64 #38905

@jbrockmendel jbrockmendel added the Constructors Series/DataFrame/Index/pd.array Constructors label Jun 8, 2021
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Dec 24, 2021
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Jan 16, 2022
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Feb 6, 2022
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Mar 12, 2022
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Apr 18, 2022
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Jul 14, 2022
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Nov 20, 2022
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Jan 26, 2023
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

pandas/tests/window/test_rolling.py also gets an i386 xfail for
rounding error that may be x87 excess precision

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Jan 26, 2023
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

pandas/tests/window/test_rolling.py also gets an i386 xfail for
rounding error that may be x87 excess precision

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Feb 2, 2023
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

pandas/tests/window/test_rolling.py also gets an i386 xfail for
rounding error that may be x87 excess precision

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Mar 1, 2023
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

pandas/tests/window/test_rolling.py also gets an i386 xfail for
rounding error that may be x87 excess precision

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Dec 19, 2023
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

pandas/tests/window/test_rolling.py also gets an i386 xfail for
rounding error that may be x87 excess precision

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Dec 19, 2023
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

pandas/tests/window/test_rolling.py also gets an i386 xfail for
rounding error that may be x87 excess precision

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Feb 6, 2024
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

pandas/tests/window/test_rolling.py also gets an i386 xfail for
rounding error that may be x87 excess precision

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Feb 15, 2024
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Feb 22, 2024
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue May 25, 2024
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Jun 11, 2024
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Jul 23, 2024
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Sep 26, 2024
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
raspbian-autopush pushed a commit to raspbian-packages/pandas that referenced this issue Oct 17, 2024
We test on more architectures, so upstream's xfails are not always
correct everywhere.  On those known to fail:
arm64 xfail -> all non-x86 xfail
x86 or unconditional strict xfail -> unconditional nonstrict xfail

Author: Rebecca N. Palmer <[email protected]>
Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146
Forwarded: no


Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
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 NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants