From e7e5f456f4d7a47c76fb17cd20ca3ea037e15618 Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Tue, 26 Jul 2022 16:53:36 -0500 Subject: [PATCH] Fix memory_usage() for `ListSeries` (#11355) This PR fixes the `memory_usage()` call for `ListSeries`. This is a bugfix. https://www.github.com/rapidsai/cuspatial/pull/585 depends on this. Perhaps it can get into `branch-22.08`? Fixes #11346. Authors: - H. Thomson Comer (https://github.com/thomcom) Approvers: - Ashwin Srinath (https://github.com/shwina) - GALI PREM SAGAR (https://github.com/galipremsagar) URL: https://github.com/rapidsai/cudf/pull/11355 --- python/cudf/cudf/core/column/lists.py | 6 +++--- python/cudf/cudf/tests/test_list.py | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/python/cudf/cudf/core/column/lists.py b/python/cudf/cudf/core/column/lists.py index c6a19f374bd..32a71a31b83 100644 --- a/python/cudf/cudf/core/column/lists.py +++ b/python/cudf/cudf/core/column/lists.py @@ -70,9 +70,9 @@ def memory_usage(self): child0_size = ( current_base_child.size + 1 - current_offset ) * current_base_child.base_children[0].dtype.itemsize - current_offset = current_base_child.base_children[0][ - current_offset - ] + current_offset = current_base_child.base_children[ + 0 + ].element_indexing(current_offset) n += child0_size current_base_child = current_base_child.base_children[1] diff --git a/python/cudf/cudf/tests/test_list.py b/python/cudf/cudf/tests/test_list.py index 2d18d230cf7..8099fac4d42 100644 --- a/python/cudf/cudf/tests/test_list.py +++ b/python/cudf/cudf/tests/test_list.py @@ -812,3 +812,10 @@ def test_list_astype(): s2 = s.list.astype("string") assert s2.dtype == cudf.ListDtype(cudf.ListDtype("string")) assert_eq(s.list.leaves.astype("string"), s2.list.leaves) + + +def test_memory_usage(): + s1 = cudf.Series([[1, 2], [3, 4]]) + assert s1.memory_usage() == 44 + s2 = cudf.Series([[[[1, 2]]], [[[3, 4]]]]) + assert s2.memory_usage() == 68