diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 17cac3593a3..08a30729e7c 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -1339,8 +1339,14 @@ def _slice(self: T, arg: slice) -> T: @_cudf_nvtx_annotate def memory_usage(self, index=True, deep=False): - return Series( - {str(k): v for k, v in super().memory_usage(index, deep).items()} + mem_usage = [col.memory_usage for col in self._data.columns] + names = [str(name) for name in self._data.names] + if index: + mem_usage.append(self._index.memory_usage()) + names.append("Index") + return Series._from_data( + data={None: as_column(mem_usage)}, + index=as_index(names), ) @_cudf_nvtx_annotate diff --git a/python/cudf/cudf/core/frame.py b/python/cudf/cudf/core/frame.py index a84606b0953..75c6e4d0964 100644 --- a/python/cudf/cudf/core/frame.py +++ b/python/cudf/cudf/core/frame.py @@ -339,12 +339,7 @@ def memory_usage(self, deep=False): ------- The total bytes used. """ - if deep: - warnings.warn( - "The deep parameter is ignored and is only included " - "for pandas compatibility." - ) - return {name: col.memory_usage for name, col in self._data.items()} + raise NotImplementedError def __len__(self): return self._num_rows diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index 7df5be3f692..a31fe4c3b99 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -914,7 +914,7 @@ def _concat(cls, objs): @_cudf_nvtx_annotate def memory_usage(self, deep=False): - return sum(super().memory_usage(deep=deep).values()) + return self._column.memory_usage @_cudf_nvtx_annotate def equals(self, other, **kwargs): diff --git a/python/cudf/cudf/core/indexed_frame.py b/python/cudf/cudf/core/indexed_frame.py index c5c2322d95a..458fc16c511 100644 --- a/python/cudf/cudf/core/indexed_frame.py +++ b/python/cudf/cudf/core/indexed_frame.py @@ -704,10 +704,7 @@ def memory_usage(self, index=True, deep=False): >>> s.memory_usage(index=False) 24 """ - usage = super().memory_usage(deep=deep) - if index: - usage["Index"] = self.index.memory_usage() - return usage + raise NotImplementedError def hash_values(self, method="murmur3"): """Compute the hash of values in this column. diff --git a/python/cudf/cudf/core/multiindex.py b/python/cudf/cudf/core/multiindex.py index 39228f034d4..d80fb00942b 100644 --- a/python/cudf/cudf/core/multiindex.py +++ b/python/cudf/cudf/core/multiindex.py @@ -1474,7 +1474,7 @@ def _clean_nulls_from_index(self): @_cudf_nvtx_annotate def memory_usage(self, deep=False): - usage = sum(super().memory_usage(deep=deep).values()) + usage = sum(col.memory_usage for col in self._data.columns) if self.levels: for level in self.levels: usage += level.memory_usage(deep=deep) diff --git a/python/cudf/cudf/core/series.py b/python/cudf/cudf/core/series.py index 0ea02edb924..8748b9775be 100644 --- a/python/cudf/cudf/core/series.py +++ b/python/cudf/cudf/core/series.py @@ -856,7 +856,9 @@ def to_frame(self, name=None): @_cudf_nvtx_annotate def memory_usage(self, index=True, deep=False): - return sum(super().memory_usage(index, deep).values()) + return self._column.memory_usage + ( + self._index.memory_usage() if index else 0 + ) @_cudf_nvtx_annotate def __array_function__(self, func, types, args, kwargs): diff --git a/python/dask_cudf/dask_cudf/backends.py b/python/dask_cudf/dask_cudf/backends.py index d1edfb071a2..36e3416c8a3 100644 --- a/python/dask_cudf/dask_cudf/backends.py +++ b/python/dask_cudf/dask_cudf/backends.py @@ -398,7 +398,10 @@ def group_split_cudf(df, c, k, ignore_index=False): @sizeof_dispatch.register(cudf.DataFrame) @_dask_cudf_nvtx_annotate def sizeof_cudf_dataframe(df): - return int(df.memory_usage().sum()) + return int( + sum(col.memory_usage for col in df._data.columns) + + df._index.memory_usage() + ) @sizeof_dispatch.register((cudf.Series, cudf.BaseIndex))