Skip to content

PERF: fix performance regression in memory_usage(deep=True) for object dtype #33102

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 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions asv_bench/benchmarks/frame_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,17 @@ def time_select_dtypes(self, n):
self.df.select_dtypes(include="int")


class MemoryUsage:
def setup(self):
self.df = DataFrame(np.random.randn(100000, 2), columns=list("AB"))
self.df2 = self.df.copy()
self.df2["A"] = self.df2["A"].astype("object")

def time_memory_usage(self):
self.df.memory_usage(deep=True)

def time_memory_usage_object_dtype(self):
self.df2.memory_usage(deep=True)


from .pandas_vb_common import setup # noqa: F401 isort:skip
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ def memory_usage(self, deep=False):

v = self.array.nbytes
if deep and is_object_dtype(self) and not PYPY:
v += lib.memory_usage_of_objects(self.array)
v += lib.memory_usage_of_objects(self._values)
return v

@doc(
Expand Down