-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
BUG / CoW: also return new object in case of null slice for both rows and columsn (.(i)loc[:, :]) #49469
BUG / CoW: also return new object in case of null slice for both rows and columsn (.(i)loc[:, :]) #49469
Conversation
… and columsn (.(i)loc[:, :])
Yeah it would be nice if there was a consistency in the returned object by whatever method if the entire object is sliced |
So shall I change this for 2.0 also in the default mode? (so as small breaking change) @jbrockmendel thoughts? |
I like this idea. |
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. |
pandas/tests/indexing/test_loc.py::TestLocBaseIndependent::test_identity_slice_returns_new_object failing |
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. |
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 returnsdf
(this doesn't happen fordf.(i)loc[:]
ordf[:]
, where only a single dimension gets indexed)Given the current inconsistency with
df.loc[:, :]
vsdf.loc[:]
, we could also consider changing this for 2.0 for the default behaviour as well, and not just for when CoW is enabled?doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.xref #48998