From 56c4a2e810b5098f8828a18ad5f8330ffffddfb6 Mon Sep 17 00:00:00 2001 From: Charles Blackmon-Luca <20627856+charlesbluca@users.noreply.github.com> Date: Fri, 30 Jul 2021 16:39:14 -0400 Subject: [PATCH] Avoid index equality check in `_CPackedColumns.from_py_table()` (#8917) Avoids a call to `Index.equals()` when making the choice whether or not to pack a table's index in `_CPackedColumns.from_py_table()`, as this was taking up a large amount of time in the packing process: ![image](https://user-images.githubusercontent.com/20627856/127695407-ec1784cb-49c8-4c40-8e04-47a18794d9d4.png) With this PR: ![image](https://user-images.githubusercontent.com/20627856/127695445-c30280a6-d51f-4698-b6df-a02bdf83aa1d.png) Authors: - Charles Blackmon-Luca (https://github.com/charlesbluca) Approvers: - https://github.com/brandon-b-miller URL: https://github.com/rapidsai/cudf/pull/8917 --- python/cudf/cudf/_lib/copying.pyx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/_lib/copying.pyx b/python/cudf/cudf/_lib/copying.pyx index 87a8aeaaa26..d114a04eec4 100644 --- a/python/cudf/cudf/_lib/copying.pyx +++ b/python/cudf/cudf/_lib/copying.pyx @@ -795,8 +795,11 @@ cdef class _CPackedColumns: cdef _CPackedColumns p = _CPackedColumns.__new__(_CPackedColumns) - if keep_index and not input_table.index.equals( - RangeIndex(start=0, stop=len(input_table), step=1) + if keep_index and ( + not isinstance(input_table.index, RangeIndex) + or input_table.index.start != 0 + or input_table.index.stop != len(input_table) + or input_table.index.step != 1 ): input_table_view = input_table.view() p.index_names = input_table._index_names