-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: can_hold_element size checks on ints/floats #45273
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: can_hold_element size checks on ints/floats #45273
Conversation
jbrockmendel
commented
Jan 8, 2022
•
edited
Loading
edited
- closes Column dtype change on write of improper value #26049
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
df = DataFrame([1, 2, 3, 4], columns=["col1"], dtype="uint8") | ||
df.loc[2, "col1"] = 300 # value that can't be held in uint8 | ||
|
||
# TODO: would be better to get uint16? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no i think this is fine, fine-grain upcasting is nice but we don't do it generally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The answer is going to end up being "yes" as a side-effect of other upcoming bugfixes.
prob needs a whatsnew |
@@ -1852,16 +1852,23 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any: | |||
tipo = maybe_infer_dtype_type(element) | |||
|
|||
if dtype.kind in ["i", "u"]: | |||
info = np.iinfo(dtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Not needed until after elif is_integer(element) or (is_float(element) and element.is_integer()):
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. will fix in an upcoming CLN branch (since getting the CI to green is a PITA these days)