Skip to content

Bounds checks for IntegerArray #21796

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
TomAugspurger opened this issue Jul 7, 2018 · 2 comments · Fixed by #42267
Closed

Bounds checks for IntegerArray #21796

TomAugspurger opened this issue Jul 7, 2018 · 2 comments · Fixed by #42267
Assignees
Labels
good first issue NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@TomAugspurger
Copy link
Contributor

On the current PR there are a couple "issues" with handling out of bounds values.

This follows NumPy's behavior, but is maybe not what the user wants

In [18]: pd.core.arrays.IntegerArray([-1, 2, 3], dtype=pd.core.arrays.integer.UInt16Dtype)
Out[18]: IntegerArray([65535, 2, 3], dtype='UInt16')
In [19]: x = pd.core.arrays.IntegerArray([-1, 2, 3], dtype=pd.core.arrays.integer.UInt16Dtype)

In [20]: x[0] = -1

In [21]: x
Out[21]: IntegerArray([65535, 2, 3], dtype='UInt16')

These could perhaps raise a ValueError instead.

xref #21160

@TomAugspurger TomAugspurger added Dtype Conversions Unexpected or buggy dtype conversions Numeric Operations Arithmetic, Comparison, and Logical operations ExtensionArray Extending pandas with custom dtypes or arrays. labels Jul 7, 2018
@jbrockmendel jbrockmendel added the Constructors Series/DataFrame/Index/pd.array Constructors label Jun 7, 2021
@mroeschke
Copy link
Member

Looks like this correctly raises a TypeError now. Could use a test

In [7]: pd.array([-1, 2, 3], dtype='UInt16')
TypeError: cannot safely cast non-equivalent int64 to uint16

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Constructors Series/DataFrame/Index/pd.array Constructors Dtype Conversions Unexpected or buggy dtype conversions ExtensionArray Extending pandas with custom dtypes or arrays. Numeric Operations Arithmetic, Comparison, and Logical operations labels Jun 20, 2021
@TAJD
Copy link
Contributor

TAJD commented Jun 27, 2021

take

TAJD added a commit to TAJD/pandas that referenced this issue Jun 27, 2021
@jreback jreback added this to the 1.4 milestone Jul 1, 2021
@jreback jreback added the NA - MaskedArrays Related to pd.NA and nullable extension arrays label Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants