Skip to content

Conversation

jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Nov 2, 2022

Related to #49450 (also ensuring we always return new objects from indexing operations, but for a different case).

Currently, there is the specific corner case of df.(i)loc[:, :] that just returns df (this doesn't happen for df.(i)loc[:] or df[:], where only a single dimension gets indexed)

Given the current inconsistency with df.loc[:, :] vs df.loc[:], we could also consider changing this for 2.0 for the default behaviour as well, and not just for when CoW is enabled?

xref #48998

@jorisvandenbossche jorisvandenbossche added Indexing Related to indexing on series/frames, not to indexes themselves Copy / view semantics labels Nov 2, 2022
@mroeschke
Copy link
Member

Given the current inconsistency with df.loc[:, :] vs df.loc[:], we could also consider changing this for 2.0 for the default behaviour as well, and not just for when CoW is enabled?

Yeah it would be nice if there was a consistency in the returned object by whatever method if the entire object is sliced

@jorisvandenbossche
Copy link
Member Author

So shall I change this for 2.0 also in the default mode? (so as small breaking change) @jbrockmendel thoughts?

@jbrockmendel
Copy link
Member

So shall I change this for 2.0 also in the default mode? (so as small breaking change)

I like this idea.

@jorisvandenbossche
Copy link
Member Author

OK, then I updated this PR to have this new behaviour for all cases (removed the check for CoW enabled), and added a whatsnew note mentioning it as a small API change.

@jbrockmendel
Copy link
Member

pandas/tests/indexing/test_loc.py::TestLocBaseIndependent::test_identity_slice_returns_new_object failing

@jorisvandenbossche
Copy link
Member Author

Ah, that was the edit I made to the test when assuming this is only changed for CoW, now it is always a new object. Should be fixed now.

@jorisvandenbossche jorisvandenbossche merged commit c35eca3 into pandas-dev:main Dec 9, 2022
@jorisvandenbossche jorisvandenbossche deleted the cow-null-slice-all-dims branch December 9, 2022 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Copy / view semantics 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