Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate delim_whitespace in read_csv for pandas 2.2 #14986

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion python/cudf/cudf/io/csv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2018-2023, NVIDIA CORPORATION.
# Copyright (c) 2018-2024, NVIDIA CORPORATION.

import warnings
from collections import abc
from io import BytesIO, StringIO

Expand Down Expand Up @@ -55,6 +56,13 @@ def read_csv(
):
"""{docstring}"""

if delim_whitespace is not False:
warnings.warn(
"The 'delim_whitespace' keyword in pd.read_csv is deprecated and "
"will be removed in a future version. Use ``sep='\\s+'`` instead",
FutureWarning,
)

if use_python_file_object and bytes_per_thread is not None:
raise ValueError(
"bytes_per_thread is only supported when "
Expand Down
28 changes: 20 additions & 8 deletions python/cudf/cudf/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@

import cudf
from cudf import read_csv
from cudf.core._compat import PANDAS_GE_200
from cudf.testing._utils import assert_eq, assert_exceptions_equal
from cudf.core._compat import PANDAS_GE_200, PANDAS_GE_220
from cudf.testing._utils import (
assert_eq,
assert_exceptions_equal,
expect_warning_if,
)


def make_numeric_dataframe(nrows, dtype):
Expand Down Expand Up @@ -1263,20 +1267,28 @@ def test_csv_reader_delim_whitespace():
buffer = "1 2 3\n4 5 6"

# with header row
cu_df = read_csv(StringIO(buffer), delim_whitespace=True)
pd_df = pd.read_csv(StringIO(buffer), delim_whitespace=True)
with pytest.warns(FutureWarning):
cu_df = read_csv(StringIO(buffer), delim_whitespace=True)
with expect_warning_if(PANDAS_GE_220):
pd_df = pd.read_csv(StringIO(buffer), delim_whitespace=True)
assert_eq(pd_df, cu_df)

# without header row
cu_df = read_csv(StringIO(buffer), delim_whitespace=True, header=None)
pd_df = pd.read_csv(StringIO(buffer), delim_whitespace=True, header=None)
with pytest.warns(FutureWarning):
cu_df = read_csv(StringIO(buffer), delim_whitespace=True, header=None)
with expect_warning_if(PANDAS_GE_220):
pd_df = pd.read_csv(
StringIO(buffer), delim_whitespace=True, header=None
)
assert pd_df.shape == cu_df.shape

# should raise an error if used with delimiter or sep
with pytest.raises(ValueError):
read_csv(StringIO(buffer), delim_whitespace=True, delimiter=" ")
with pytest.warns(FutureWarning):
read_csv(StringIO(buffer), delim_whitespace=True, delimiter=" ")
with pytest.raises(ValueError):
read_csv(StringIO(buffer), delim_whitespace=True, sep=" ")
with pytest.warns(FutureWarning):
read_csv(StringIO(buffer), delim_whitespace=True, sep=" ")


def test_csv_reader_unnamed_cols():
Expand Down