Skip to content
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

REGR: Adding a row via DataFrame.at #48296

Closed
rhshadrach opened this issue Aug 29, 2022 · 3 comments · Fixed by #48324
Closed

REGR: Adding a row via DataFrame.at #48296

rhshadrach opened this issue Aug 29, 2022 · 3 comments · Fixed by #48324
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@rhshadrach
Copy link
Member

df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
df.at[2] = [5, 6]

On 1.4.x, this gives

     a    b
0  1.0  3.0
1  2.0  4.0
2  5.0  6.0

whereas on 1.5.0rc0 it gives pandas.errors.InvalidIndexError: slice(None, None, None). I didn't any mention of this in the whatsnew, and a git bisect points at #47074; cc @jorisvandenbossche.

The docs of DataFrame.at explicitly say a KeyError is raised when the label is not in the frame. It seems to me this operation should not be supported, and can be considered a bugfix, but would be better to raise KeyError: label 2 not found.

@rhshadrach rhshadrach added Bug Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version Needs Discussion Requires discussion from core team before further action labels Aug 29, 2022
@rhshadrach rhshadrach added this to the 1.5 milestone Aug 29, 2022
@phofl
Copy link
Member

phofl commented Aug 29, 2022

Hm I think InvalidIndexError is ok too, since at is for one value only and this tries to update 2

although the message is not optimal

@rhshadrach
Copy link
Member Author

rhshadrach commented Aug 29, 2022

I see; the slice(None, None, None) is referring to the columns - thanks. That makes sense, but this doesn't raise on main:

df = pd.DataFrame({'a': [1, 2]})
df.at[3, 'a'] = 7

and instead adds a row. I believe this should raise a KeyError, and think it would be preferable for the OP example to also raise a KeyError. If the key were to exist, InvalidIndexError in the OP makes sense to me (perhaps with a better message if possible).

I plan to add a note in the whatsnew in the indexing bugfixes section to close this issue and open a new issue on changing the behavior of .at, but I think the behavior change should wait until after the 1.5. release.

@phofl
Copy link
Member

phofl commented Aug 29, 2022

This is probably related to #48224 somehow. Maybe you could combine them when opening a new issue

@rhshadrach rhshadrach added Needs Tests Unit test(s) needed to prevent regressions and removed Needs Discussion Requires discussion from core team before further action labels Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants