Skip to content

Commit

Permalink
Remove dataframe protocol (#17909)
Browse files Browse the repository at this point in the history
Follow-up to #17736

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #17909
  • Loading branch information
vyasr authored Feb 6, 2025
1 parent 2da273c commit 92cf560
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 1,254 deletions.
1 change: 0 additions & 1 deletion docs/cudf/source/user_guide/api_docs/general_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Top-level conversions
:toctree: api/

to_numeric
from_dataframe
from_dlpack
from_pandas

Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2024, NVIDIA CORPORATION.
# Copyright (c) 2018-2025, NVIDIA CORPORATION.

# If libcudf was installed as a wheel, we must request it to load the library symbols.
# Otherwise, we assume that the library was installed in a system path that ld can find.
Expand Down Expand Up @@ -36,7 +36,7 @@
from cudf.api.types import dtype
from cudf.core.algorithms import factorize, unique
from cudf.core.cut import cut
from cudf.core.dataframe import DataFrame, from_dataframe, from_pandas, merge
from cudf.core.dataframe import DataFrame, from_pandas, merge
from cudf.core.dtypes import (
CategoricalDtype,
Decimal32Dtype,
Expand Down
45 changes: 1 addition & 44 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import pandas as pd
import pyarrow as pa
from nvtx import annotate
from packaging import version
from pandas.io.formats import console
from pandas.io.formats.printing import pprint_thing
from typing_extensions import Self, assert_never
Expand All @@ -48,7 +47,7 @@
is_scalar,
is_string_dtype,
)
from cudf.core import column, df_protocol, indexing_utils, reshape
from cudf.core import column, indexing_utils, reshape
from cudf.core._compat import PANDAS_LT_300
from cudf.core.buffer import acquire_spill_lock, as_buffer
from cudf.core.column import (
Expand Down Expand Up @@ -5564,16 +5563,6 @@ def from_pandas(cls, dataframe, nan_as_null=no_default):
# Checks duplicate columns and sets column metadata
df.columns = dataframe.columns
return df
elif hasattr(dataframe, "__dataframe__"):
# TODO: Probably should be handled in the constructor as
# this isn't pandas specific
assert version.parse(cudf.__version__) < version.parse("25.04.00")
warnings.warn(
"Support for loading dataframes via the `__dataframe__` interchange "
"protocol is deprecated",
FutureWarning,
)
return from_dataframe(dataframe, allow_copy=True)
else:
raise TypeError(
f"Could not construct DataFrame from {type(dataframe)}"
Expand Down Expand Up @@ -7730,15 +7719,6 @@ def pct_change(
periods=periods, freq=freq, **kwargs
)

def __dataframe__(
self, nan_as_null: bool = False, allow_copy: bool = True
):
assert version.parse(cudf.__version__) < version.parse("25.04.00")
warnings.warn("Using `__dataframe__` is deprecated", FutureWarning)
return df_protocol.__dataframe__(
self, nan_as_null=nan_as_null, allow_copy=allow_copy
)

def nunique(self, axis=0, dropna: bool = True) -> Series:
"""
Count number of distinct elements in specified axis.
Expand Down Expand Up @@ -8183,29 +8163,6 @@ def from_pylibcudf(cls, table: plc.Table, metadata: dict) -> Self:
return df


def from_dataframe(df, allow_copy: bool = False) -> DataFrame:
"""
Build a :class:`DataFrame` from an object supporting the dataframe interchange protocol.
.. note::
If you have a ``pandas.DataFrame``, use :func:`from_pandas` instead.
Parameters
----------
df : DataFrameXchg
Object supporting the interchange protocol, i.e. ``__dataframe__`` method.
allow_copy : bool, default: True
Whether to allow copying the memory to perform the conversion
(if false then zero-copy approach is requested).
Returns
-------
:class:`DataFrame`
"""
return df_protocol.from_dataframe(df, allow_copy=allow_copy)


def make_binop_func(op, postprocess=None):
# This function is used to wrap binary operations in Frame with an
# appropriate API for DataFrame as required for pandas compatibility. The
Expand Down
Loading

0 comments on commit 92cf560

Please sign in to comment.