From c0816e9c8c7e84a861eacfa53ceb8442fd87995a Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Thu, 17 Aug 2023 11:58:03 -0700 Subject: [PATCH] Use pylibcudf only in pure Python mode --- python/cudf/cudf/_lib/column.pxd | 3 +-- python/cudf/cudf/_lib/column.pyx | 13 +++++-------- python/cudf/cudf/_lib/copying.pyx | 4 ++-- python/cudf/cudf/_lib/types.pxd | 3 +-- python/cudf/cudf/_lib/types.pyx | 9 ++++----- python/cudf/cudf/_lib/utils.pxd | 3 +-- python/cudf/cudf/_lib/utils.pyx | 4 +--- 7 files changed, 15 insertions(+), 24 deletions(-) diff --git a/python/cudf/cudf/_lib/column.pxd b/python/cudf/cudf/_lib/column.pxd index fbdf6288538..7ffb55a6cc6 100644 --- a/python/cudf/cudf/_lib/column.pxd +++ b/python/cudf/cudf/_lib/column.pxd @@ -7,7 +7,6 @@ from libcpp.memory cimport unique_ptr from rmm._lib.device_buffer cimport device_buffer -from cudf._lib cimport pylibcudf from cudf._lib.cpp.column.column cimport column from cudf._lib.cpp.column.column_view cimport column_view, mutable_column_view from cudf._lib.cpp.types cimport size_type @@ -30,7 +29,7 @@ cdef class Column: cdef column_view _view(self, size_type null_count) except * cdef column_view view(self) except * cdef mutable_column_view mutable_view(self) except * - cpdef pylibcudf.Column to_pylibcudf(self, mode: Literal["read", "write"]) + cpdef to_pylibcudf(self, mode: Literal["read", "write"]) @staticmethod cdef Column from_unique_ptr( diff --git a/python/cudf/cudf/_lib/column.pyx b/python/cudf/cudf/_lib/column.pyx index 36a5ccd9140..a320f1c3425 100644 --- a/python/cudf/cudf/_lib/column.pyx +++ b/python/cudf/cudf/_lib/column.pyx @@ -11,9 +11,6 @@ import rmm import cudf import cudf._lib as libcudf from cudf._lib import pylibcudf - -from cudf._lib cimport pylibcudf - from cudf.api.types import is_categorical_dtype, is_datetime64tz_dtype from cudf.core.buffer import ( Buffer, @@ -447,7 +444,7 @@ cdef class Column: # underlying buffers as exposed before this function can itself be exposed # publicly. User requests to convert to pylibcudf must assume that the # data may be modified afterwards. - cpdef pylibcudf.Column to_pylibcudf(self, mode: Literal["read", "write"]): + cpdef to_pylibcudf(self, mode: Literal["read", "write"]): """Convert this Column to a pylibcudf.Column. This function will generate a pylibcudf Column pointing to the same @@ -477,9 +474,9 @@ cdef class Column: else: col = self - cdef pylibcudf.DataType dtype = dtype_to_pylibcudf_type(col.dtype) + dtype = dtype_to_pylibcudf_type(col.dtype) - cdef pylibcudf.gpumemoryview data = None + data = None if col.base_data is not None: cai = cuda_array_interface_wrapper( ptr=col.base_data.get_ptr(mode=mode), @@ -488,7 +485,7 @@ cdef class Column: ) data = pylibcudf.gpumemoryview(cai) - cdef pylibcudf.gpumemoryview mask = None + mask = None if self.nullable: # TODO: Are we intentionally use self's mask instead of col's? # Where is the mask stored for categoricals? @@ -587,7 +584,7 @@ cdef class Column: # TODO: Actually support exposed data pointers. @staticmethod def from_pylibcudf( - pylibcudf.Column col, bint data_ptr_exposed=False + col, bint data_ptr_exposed=False ): """Create a Column from a pylibcudf.Column. diff --git a/python/cudf/cudf/_lib/copying.pyx b/python/cudf/cudf/_lib/copying.pyx index 944a80158df..f57bc15ed57 100644 --- a/python/cudf/cudf/_lib/copying.pyx +++ b/python/cudf/cudf/_lib/copying.pyx @@ -11,9 +11,9 @@ from libcpp.vector cimport vector from rmm._lib.device_buffer cimport DeviceBuffer import cudf +from cudf._lib import pylibcudf from cudf.core.buffer import Buffer, acquire_spill_lock, as_buffer -from cudf._lib cimport pylibcudf from cudf._lib.column cimport Column from cudf._lib.scalar import as_device_scalar @@ -174,7 +174,7 @@ def gather( Column gather_map, bool nullify=False ): - cdef pylibcudf.Table tbl = pylibcudf.copying.gather( + tbl = pylibcudf.copying.gather( pylibcudf.Table([col.to_pylibcudf(mode="read") for col in columns]), gather_map.to_pylibcudf(mode="read"), pylibcudf.copying.OutOfBoundsPolicy.NULLIFY if nullify diff --git a/python/cudf/cudf/_lib/types.pxd b/python/cudf/cudf/_lib/types.pxd index 1eeaa23c260..a95db84ceff 100644 --- a/python/cudf/cudf/_lib/types.pxd +++ b/python/cudf/cudf/_lib/types.pxd @@ -4,7 +4,6 @@ from libc.stdint cimport int32_t from libcpp cimport bool cimport cudf._lib.cpp.types as libcudf_types -from cudf._lib cimport pylibcudf from cudf._lib.cpp.column.column_view cimport column_view from cudf._lib.cpp.lists.lists_column_view cimport lists_column_view @@ -18,5 +17,5 @@ ctypedef bool underlying_type_t_null_policy cdef dtype_from_column_view(column_view cv) cdef libcudf_types.data_type dtype_to_data_type(dtype) except * -cpdef pylibcudf.DataType dtype_to_pylibcudf_type(dtype) +cpdef dtype_to_pylibcudf_type(dtype) cdef bool is_decimal_type_id(libcudf_types.type_id tid) except * diff --git a/python/cudf/cudf/_lib/types.pyx b/python/cudf/cudf/_lib/types.pyx index d6396157af4..8594e37ac4a 100644 --- a/python/cudf/cudf/_lib/types.pyx +++ b/python/cudf/cudf/_lib/types.pyx @@ -17,7 +17,6 @@ from cudf._lib.types cimport ( import cudf from cudf._lib import pylibcudf -from cudf._lib cimport pylibcudf size_type_dtype = np.dtype("int32") @@ -257,7 +256,7 @@ cdef libcudf_types.data_type dtype_to_data_type(dtype) except *: else: return libcudf_types.data_type(tid) -cpdef pylibcudf.DataType dtype_to_pylibcudf_type(dtype): +cpdef dtype_to_pylibcudf_type(dtype): if cudf.api.types.is_list_dtype(dtype): return pylibcudf.DataType(pylibcudf.TypeId.LIST) elif cudf.api.types.is_struct_dtype(dtype): @@ -282,7 +281,7 @@ cdef bool is_decimal_type_id(libcudf_types.type_id tid) except *: ) -def dtype_from_pylibcudf_lists_column(pylibcudf.Column col): +def dtype_from_pylibcudf_lists_column(col): child = col.list_view().child() tid = child.type().id() @@ -296,7 +295,7 @@ def dtype_from_pylibcudf_lists_column(pylibcudf.Column col): ) -def dtype_from_pylibcudf_structs_column(pylibcudf.Column col): +def dtype_from_pylibcudf_structs_column(col): fields = { str(i): dtype_from_pylibcudf_column(col.child(i)) for i in range(col.num_children()) @@ -304,7 +303,7 @@ def dtype_from_pylibcudf_structs_column(pylibcudf.Column col): return cudf.StructDtype(fields) -def dtype_from_pylibcudf_column(pylibcudf.Column col): +def dtype_from_pylibcudf_column(col): type_ = col.type() tid = type_.id() diff --git a/python/cudf/cudf/_lib/utils.pxd b/python/cudf/cudf/_lib/utils.pxd index f2cdc110b64..653fa8f2b8b 100644 --- a/python/cudf/cudf/_lib/utils.pxd +++ b/python/cudf/cudf/_lib/utils.pxd @@ -4,7 +4,6 @@ from libcpp.memory cimport unique_ptr from libcpp.string cimport string from libcpp.vector cimport vector -from cudf._lib cimport pylibcudf from cudf._lib.cpp.column.column cimport column_view from cudf._lib.cpp.table.table cimport table, table_view @@ -19,4 +18,4 @@ cdef table_view table_view_from_columns(columns) except * cdef table_view table_view_from_table(tbl, ignore_index=*) except* cdef columns_from_unique_ptr(unique_ptr[table] c_tbl) cdef columns_from_table_view(table_view tv, object owners) -cdef columns_from_pylibcudf_table(pylibcudf.Table table) +cdef columns_from_pylibcudf_table(tbl) diff --git a/python/cudf/cudf/_lib/utils.pyx b/python/cudf/cudf/_lib/utils.pyx index 4815c705958..03982a58517 100644 --- a/python/cudf/cudf/_lib/utils.pyx +++ b/python/cudf/cudf/_lib/utils.pyx @@ -11,7 +11,6 @@ from libcpp.string cimport string from libcpp.utility cimport move from libcpp.vector cimport vector -from cudf._lib cimport pylibcudf from cudf._lib.column cimport Column from cudf._lib.cpp.column.column cimport column, column_view from cudf._lib.cpp.table.table cimport table @@ -247,7 +246,7 @@ cdef columns_from_unique_ptr( return columns -cdef columns_from_pylibcudf_table(pylibcudf.Table tbl): +cdef columns_from_pylibcudf_table(tbl): """Convert a pylibcudf table into list of columns. Parameters @@ -260,7 +259,6 @@ cdef columns_from_pylibcudf_table(pylibcudf.Table tbl): list[Column] A list of columns. """ - cdef pylibcudf.Column plc return [Column.from_pylibcudf(plc) for plc in tbl.columns()]