Skip to content

BUG: setting float on integer column with DataFrame.at casts the value to integer. #37477

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
3 tasks done
erfannariman opened this issue Oct 28, 2020 · 1 comment · Fixed by #45154
Closed
3 tasks done
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@erfannariman
Copy link
Member

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

In [5]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [3, 4, 5]})

In [6]: df
Out[6]: 
   A  B
0  1  3
1  2  4
2  3  5

In [7]: df.at[1, 'B'] = 1.2

In [8]: df
Out[8]: 
   A  B
0  1  3
1  2  1
2  3  5

Problem description

DataFrame.at sets the new value but casts it to integer.

Expected output

This is not the issue with loc:

In [9]: df.loc[1, 'B'] = 1.2

In [10]: df
Out[10]: 
   A    B
0  1  3.0
1  2  1.2
2  3  5.0
@erfannariman erfannariman added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 28, 2020
@erfannariman
Copy link
Member Author

erfannariman commented Oct 30, 2020

This seems to happen in pandas/core/frame.py at line. Changing:

series._values[loc] = value

To

series.loc[loc] = value

Fixes the issue, but then fails some tests.

@mroeschke mroeschke added Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 14, 2021
@jreback jreback added this to the 1.4 milestone Jan 3, 2022
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 Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants