Skip to content

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

Merged
merged 3 commits into from
Jan 10, 2022

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Jan 8, 2022

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?
Copy link
Contributor

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

Copy link
Member Author

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.

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions labels Jan 8, 2022
@jreback jreback added this to the 1.5 milestone Jan 8, 2022
@jreback
Copy link
Contributor

jreback commented Jan 8, 2022

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)
Copy link
Member

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()):?

Copy link
Member Author

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)

@jreback jreback merged commit 37c3343 into pandas-dev:master Jan 10, 2022
@jbrockmendel jbrockmendel deleted the bug-smallintsetitemupcast branch January 10, 2022 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Column dtype change on write of improper value
3 participants