Skip to content

BUG: Changed .at to not set values that do not exist yet in a DataFrame #48323 #48542

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
wants to merge 1 commit into from

Conversation

srotondo
Copy link
Contributor

@mroeschke
Copy link
Member

Does this overlap with #48362? If so I would recommend allowing @johannes-mueller to continue with that PR first

@srotondo
Copy link
Contributor Author

Does this overlap with #48362? If so I would recommend allowing @johannes-mueller to continue with that PR first

In that PR, @johannes-mueller stated that if the behavior was made so that .at can't add new rows or columns that his PR shouldn't be merged because it is superfluous. I've linked this PR to his PR so that a decision can be made on the final outcome.

@mroeschke mroeschke added the Indexing Related to indexing on series/frames, not to indexes themselves label Sep 14, 2022
Copy link
Contributor

@johannes-mueller johannes-mueller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this one. It can supersede #48362.

@@ -234,3 +237,9 @@ def test_at_categorical_integers(self):
for key in [0, 1]:
with pytest.raises(KeyError, match=str(key)):
df.at[key, key]

def test_at_does_not_expand(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have two tests here, one for expansion in column axis and another one for expansion in index axis.

expected = DataFrame(
[[10, 10], [0, 0], [0, 0]],
columns=MultiIndex.from_tuples([("a", 0), ("a", 1)]),
)
tm.assert_frame_equal(df, expected)
with pytest.raises(TypeError, match=""):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I would put this into a separate test. One test for the happy path and one for the failing path. YMMV

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to split this because this isn't actually a test I created, but one I had to modify based on the code change, so I'd like to keep the change as small as I reasonably can.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, fair enough.

Personally I am really reluctant to modify existing tests. So I would rather add a new one. YMMV

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #48542, I think this needs deprecating. It is documented in the User Guide, so it would be a breaking change.

@srotondo
Copy link
Contributor Author

From #48542, I think this needs deprecating. It is documented in the User Guide, so it would be a breaking change.

@rhshadrach How does the deprecation process work in Pandas? Is there something I should do, or does it just mean that someone else needs to announce the change before accepting my PR? (Note that my PR does include a change to the user guide to make it more accurate.)

@rhshadrach
Copy link
Member

How does the deprecation process work in Pandas?

The behavior that is to be deprecated needs to raise a FutuerWarning with a message informing the user that the behavior will change. If possible, it is good to give alternatives (e.g. pd.concat) in the message. We then wait until the next major release to change the behavior.

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Oct 28, 2022
@rhshadrach
Copy link
Member

Closing as stale. @srotondo - if you'd like to pick this back up and deprecate the behavior, we can reopen.

@rhshadrach rhshadrach closed this Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DataFrame.at allows adding new rows to a DataFrame
5 participants