Skip to content
Open
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
1 change: 0 additions & 1 deletion python/cudf/cudf/core/buffer/spillable_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def mark_exposed(self) -> None:

This also unspills the buffer (unspillable buffers cannot be spilled!).
"""

self._manager.spill_to_device_limit()
with self.lock:
if not self.exposed:
Expand Down
19 changes: 17 additions & 2 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import rmm

import cudf
from cudf.api.extensions import no_default
from cudf.api.types import (
_is_categorical_dtype,
infer_dtype,
Expand Down Expand Up @@ -612,7 +613,9 @@ def from_pylibcudf(
)

@classmethod
def from_cuda_array_interface(cls, arbitrary: Any) -> Self:
def from_cuda_array_interface(
cls, arbitrary: Any, data_ptr_exposed=no_default
) -> Self:
"""
Create a Column from an object implementing the CUDA array interface.

Expand Down Expand Up @@ -647,9 +650,11 @@ def from_cuda_array_interface(cls, arbitrary: Any) -> Self:
else:
mask = None

if data_ptr_exposed is no_default:
data_ptr_exposed = cudf.get_option("copy_on_write")
column = ColumnBase.from_pylibcudf(
plc.Column.from_cuda_array_interface(arbitrary),
data_ptr_exposed=cudf.get_option("copy_on_write"),
data_ptr_exposed=data_ptr_exposed,
)
if mask is not None:
column = column.set_mask(mask)
Expand Down Expand Up @@ -2886,6 +2891,16 @@ def as_column(
arbitrary = np.asarray(arbitrary)
else:
arbitrary = cp.asarray(arbitrary)
# Explicitly passing `data_ptr_exposed` to
# reuse existing memory created by cupy here
column = ColumnBase.from_cuda_array_interface(
arbitrary, data_ptr_exposed=False
)
if nan_as_null is not False:
column = column.nans_to_nulls()
if dtype is not None:
column = column.astype(dtype)
return column
return as_column(
arbitrary, nan_as_null=nan_as_null, dtype=dtype, length=length
)
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def as_numerical_column(self, dtype: Dtype) -> NumericalColumn:
# If the dtype is a pandas nullable extension type, we need to
# float column doesn't have any NaNs.
res = self.nans_to_nulls()
res._dtype = dtype
res._dtype = dtype # type: ignore[has-type]
return res
else:
self._dtype = dtype
Expand Down
5 changes: 4 additions & 1 deletion python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3222,7 +3222,10 @@ def set_index(
# label-like
if is_scalar(col) or isinstance(col, tuple):
if col in self._column_names:
data_to_add.append(self[col]._column)
if drop and inplace:
data_to_add.append(self[col]._column)
else:
data_to_add.append(self[col]._column.copy(deep=True))
names.append(col)
if drop:
to_drop.append(col)
Expand Down
10 changes: 8 additions & 2 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ def copy(self, name: Hashable = None, deep: bool = False) -> Self:
New index instance.
"""
name = self.name if name is None else name
col = self._column.copy(deep=True) if deep else self._column
col = self._column.copy(deep=deep)
return type(self)._from_column(col, name=name)

@_performance_tracking
Expand Down Expand Up @@ -5505,7 +5505,13 @@ def _as_index(
)
return data.copy(deep=copy)
elif isinstance(data, Index):
idx = data.copy(deep=copy).rename(name)
if not isinstance(data, cudf.RangeIndex):
idx = type(data)._from_column(
data._column.copy(deep=copy) if copy else data._column,
name=name,
)
else:
idx = data.copy(deep=copy).rename(name)
elif isinstance(data, ColumnBase):
raise ValueError("Use cudf.Index._from_column instead.")
elif isinstance(data, (pd.RangeIndex, range)):
Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,7 @@ def copy(self, deep: bool = True) -> Self:
"""
return self._from_data(
self._data.copy(deep=deep),
# Indexes are immutable so copies can always be shallow.
self.index.copy(deep=False),
self.index.copy(deep=deep),
attrs=copy.deepcopy(self.attrs) if deep else self._attrs,
)

Expand Down
4 changes: 0 additions & 4 deletions python/cudf/cudf/pandas/scripts/conftest-patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6679,10 +6679,6 @@ def pytest_unconfigure(config):
"tests/indexes/test_common.py::TestCommon::test_to_frame[uint8-new_name]",
"tests/indexes/test_common.py::test_ndarray_compat_properties[multi]",
"tests/indexes/test_common.py::test_ndarray_compat_properties[tuples]",
"tests/indexes/test_common.py::test_sort_values_invalid_na_position[nullable_int-None]",
"tests/indexes/test_common.py::test_sort_values_invalid_na_position[nullable_int-middle]",
"tests/indexes/test_common.py::test_sort_values_with_missing[nullable_int-first]",
"tests/indexes/test_common.py::test_sort_values_with_missing[nullable_int-last]",
"tests/indexes/test_datetimelike.py::TestDatetimeLike::test_argsort_matches_array[simple_index1]",
"tests/indexes/test_datetimelike.py::TestDatetimeLike::test_argsort_matches_array[simple_index2]",
"tests/indexes/test_indexing.py::TestGetIndexer::test_get_indexer_base[multi]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ def test_rename_shallow_copy():

idx = cudf.Index([1])
result = idx.rename("a")
assert idx._column is result._column
assert idx._column.base_data.get_ptr(
mode="read"
) == result._column.base_data.get_ptr(mode="read")