8000 BUG: ensure reindex / getitem to select columns properly copies data for extension dtypes by jorisvandenbossche · Pull Request #51197 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
  • Loading branch information
jorisvandenbossche committed Feb 10, 2023
commit d818c61b76d58c626ac443e92bee9c7f03da056e
A0FD
15 changes: 15 additions & 0 deletions pandas/tests/frame/methods/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ def test_reindex_copies(self):
result2 = df.reindex(columns=cols, index=df.index, copy=True)
assert not np.shares_memory(result2[0]._values, df[0]._values)

def test_reindex_copies_ea(self):
# https://github.com/pandas-dev/pandas/pull/51197
# also ensure to honor copy keyword for ExtensionDtypes
N = 10
df = DataFrame(np.random.randn(N * 10, N), dtype="Float64")
cols = np.arange(N)
np.random.shuffle(cols)

result = df.reindex(columns=cols, copy=True)
assert not np.shares_memory(result[0].array._data, df[0].array._data)

# pass both columns and index
result2 = df.reindex(columns=cols, index=df.index, copy=True)
assert not np.shares_memory(result2[0].array._data, df[0].array._data)

@td.skip_array_manager_not_yet_implemented
def test_reindex_date_fill_value(self):
# passing date to dt64 is deprecated; enforced in 2.0 to cast to object
Expand Down
0