Skip to content

.iloc[:] and .loc[:] return the original object #13873

Closed
@shoyer

Description

@shoyer

Each of these asserts should fail:

# on pandas 0.18.1
import pandas as pd

df = pd.DataFrame({'x': range(3)})
assert df.iloc[:] is df
assert df.loc[:] is df

series = df.x
assert series.iloc[:] is series
assert series.loc[:] is series

Instead, for the sake of predictability, these should always return a new DataFrame/Series, even if they reuse the same data. See here for an example of how this resulted in a user facing bug within pandas.

Thanks @mborysow for pointing this out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions