Skip to content

ENH: Use lazy copy in infer objects #50428

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

Merged
merged 33 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3c4cee3
ENH: Use lazy copy in infer objects
phofl Dec 24, 2022
db5dba1
Update test_methods.py
phofl Dec 24, 2022
9eb4d85
Merge remote-tracking branch 'upstream/main' into cow_infer_objects
phofl Jan 8, 2023
081dd29
Convert copy
phofl Jan 8, 2023
76c443b
Convert copy
phofl Jan 8, 2023
f7724ff
Remove setting
phofl Jan 8, 2023
a7b4e27
Fix
phofl Jan 8, 2023
1d4f726
Fix typing
phofl Jan 8, 2023
018cfe6
Revert unrelated change
phofl Jan 8, 2023
1696d8a
Fix
phofl Jan 8, 2023
1782fbd
Fix array manager
phofl Jan 8, 2023
8cb6355
Fix type
phofl Jan 8, 2023
cead228
Merge branch 'main' into cow_infer_objects
phofl Jan 12, 2023
47d85b3
Fix copy array manager
phofl Jan 13, 2023
a3d0a2b
Fix manager
phofl Jan 13, 2023
2e2ed0f
Merge remote-tracking branch 'upstream/main' into cow_inf_obj
phofl Jan 13, 2023
3a84382
Merge branch 'main' into cow_infer_objects
phofl Jan 17, 2023
64d550b
Merge remote-tracking branch 'upstream/main' into cow_infer_objects
phofl Jan 27, 2023
716cef8
Refactor
phofl Jan 27, 2023
f693829
Fix mypy
phofl Jan 31, 2023
97fa214
Move to cython
phofl Jan 31, 2023
c3e4e66
Merge remote-tracking branch 'upstream/main' into cow_infer_objects
phofl Feb 7, 2023
5d687dd
Merge CoW ref tracking
phofl Feb 7, 2023
f5bf65f
Refactor for new ref tracking logic
phofl Feb 7, 2023
af8af95
Merge remote-tracking branch 'upstream/main' into cow_infer_objects
phofl Feb 8, 2023
f47f6dd
Fix array manager diff
phofl Feb 8, 2023
e357b64
Fix merge conflicts
phofl Feb 8, 2023
bf1bb3b
Add todo
phofl Feb 8, 2023
5624983
Add test
phofl Feb 8, 2023
9a6d516
Adjust test
phofl Feb 8, 2023
8b0e2b0
Adjust test
phofl Feb 8, 2023
3f832ba
Adjust test
phofl Feb 8, 2023
9f11f0a
Fixup
phofl Feb 8, 2023
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
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6313,7 +6313,7 @@ def __deepcopy__(self: NDFrameT, memo=None) -> NDFrameT:
return self.copy(deep=True)

@final
def infer_objects(self: NDFrameT, copy: bool_t = True) -> NDFrameT:
def infer_objects(self: NDFrameT, copy: bool_t | None = None) -> NDFrameT:
"""
Attempt to infer better dtypes for object columns.

Expand Down
21 changes: 21 additions & 0 deletions pandas/tests/copy_view/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,27 @@ def test_head_tail(method, using_copy_on_write):
tm.assert_frame_equal(df, df_orig)


def test_infer_objects(using_copy_on_write):
df = DataFrame({"a": [1, 2], "b": "c"})
df_orig = df.copy()
df2 = df.infer_objects()

if using_copy_on_write:
assert np.shares_memory(get_array(df2, "a"), get_array(df, "a"))
assert np.shares_memory(get_array(df2, "b"), get_array(df, "b"))

else:
assert not np.shares_memory(get_array(df2, "a"), get_array(df, "a"))
assert not np.shares_memory(get_array(df2, "b"), get_array(df, "b"))

df2.iloc[0, 0] = 0
df2.iloc[0, 1] = "d"
if using_copy_on_write:
assert not np.shares_memory(get_array(df2, "a"), get_array(df, "a"))
assert not np.shares_memory(get_array(df2, "b"), get_array(df, "b"))
tm.assert_frame_equal(df, df_orig)


def test_assign(using_copy_on_write):
df = DataFrame({"a": [1, 2, 3]})
df_orig = df.copy()
Expand Down