Skip to content

BUG: Series.__setitem__ failing to cast numeric values #45121

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 2 commits into from
Dec 31, 2021

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Dec 30, 2021

  • closes #xxxx
  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry

Two cases this fixes (both tested in test_coersion)

ser = pd.Series([1, 2, 3, 4])
ser[1] = 1.1
>>> ser[1]
1.1  # <- PR
1    # <- master; note that setting with loc or iloc *does* cast


ser2 = pd.Series([1, 2, 3, 4], dtype=np.int8)
ser2[1] = np.int16(512)

>>> ser2[1]
512 # <- PR; casts to int16
0   # <- master; still np.int8; note that setting with with loc or iloc *does* cast

Downside: can_hold_element is heavier-weight than validate_numeric_casting.

@jreback
Copy link
Contributor

jreback commented Dec 30, 2021

this is a break with numpy (good) but needs a good note here

@jreback jreback added this to the 1.4 milestone Dec 30, 2021
@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves labels Dec 30, 2021
@phofl
Copy link
Member

phofl commented Dec 30, 2021

This adresses parts of #20643 I think. The Series.setitem case was not working there

@jreback
Copy link
Contributor

jreback commented Dec 31, 2021

@jbrockmendel addressing @phofl comments in followup or here?

@jbrockmendel
Copy link
Member Author

jbrockmendel commented Dec 31, 2021 via email

@jreback jreback merged commit fb9f205 into pandas-dev:master Dec 31, 2021
@jreback
Copy link
Contributor

jreback commented Dec 31, 2021

k great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants