Skip to content

Commit

Permalink
Remove legacy JSON reader from Python (#15538)
Browse files Browse the repository at this point in the history
This PR removes the `engine="cudf_legacy"` option from Python.

This is a part of #15537.

Authors:
  - Bradley Dice (https://github.com/bdice)

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

URL: #15538
  • Loading branch information
bdice authored Apr 16, 2024
1 parent c1dcc31 commit 77abf03
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 60 deletions.
23 changes: 2 additions & 21 deletions python/cudf/cudf/io/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,14 @@ def read_json(
f"or a bool, or None. Got {type(dtype)}"
)

if engine == "cudf_experimental":
raise ValueError(
"engine='cudf_experimental' support has been removed, "
"use `engine='cudf'`"
)

if engine == "cudf_legacy":
# TODO: Deprecated in 23.02, please
# give some time until(more than couple of
# releases from now) `cudf_legacy`
# support can be removed completely.
warnings.warn(
"engine='cudf_legacy' is a deprecated engine."
"This will be removed in a future release."
"Please switch to using engine='cudf'.",
FutureWarning,
)
if engine == "cudf_legacy" and not lines:
raise ValueError(f"{engine} engine only supports JSON Lines format")
if engine == "auto":
engine = "cudf" if lines else "pandas"
if engine != "cudf" and keep_quotes:
raise ValueError(
"keep_quotes='True' is supported only with engine='cudf'"
)

if engine == "cudf_legacy" or engine == "cudf":
if engine == "cudf":
if dtype is None:
dtype = True

Expand Down Expand Up @@ -117,7 +98,7 @@ def read_json(
lines,
compression,
byte_range,
engine == "cudf_legacy",
False,
keep_quotes,
mixed_types_as_string,
)
Expand Down
39 changes: 1 addition & 38 deletions python/cudf/cudf/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,6 @@ def test_json_lines_compression(tmpdir, ext, out_comp, in_comp):


@pytest.mark.filterwarnings("ignore:Using CPU")
@pytest.mark.filterwarnings(
"ignore:engine='cudf_legacy' is a deprecated engine."
)
def test_json_engine_selection():
json = "[1, 2, 3]"

Expand All @@ -519,10 +516,6 @@ def test_json_engine_selection():
for col_name in df.columns:
assert isinstance(col_name, int)

# should raise an exception
with pytest.raises(ValueError):
cudf.read_json(StringIO(json), lines=False, engine="cudf_legacy")


def test_json_bool_values():
buffer = "[true,1]\n[false,false]\n[true,true]"
Expand All @@ -541,30 +534,6 @@ def test_json_bool_values():
np.testing.assert_array_equal(pd_df.dtypes, cu_df.dtypes)


@pytest.mark.filterwarnings(
"ignore:engine='cudf_legacy' is a deprecated engine."
)
@pytest.mark.parametrize(
"buffer",
[
"[1.0,]\n[null, ]",
'{"0":1.0,"1":}\n{"0":null,"1": }',
'{ "0" : 1.0 , "1" : }\n{ "0" : null , "1" : }',
'{"0":1.0}\n{"1":}',
],
)
def test_json_null_literal(buffer):
df = cudf.read_json(StringIO(buffer), lines=True, engine="cudf_legacy")

# first column contains a null field, type should be set to float
# second column contains only empty fields, type should be set to int8
np.testing.assert_array_equal(df.dtypes, ["float64", "int8"])
np.testing.assert_array_equal(
df["0"].to_numpy(na_value=np.nan), [1.0, np.nan]
)
np.testing.assert_array_equal(df["1"].to_numpy(na_value=0), [0, 0])


def test_json_bad_protocol_string():
test_string = StringIO('{"field": "s3://path"}')

Expand Down Expand Up @@ -739,14 +708,8 @@ def test_default_integer_bitwidth(default_integer_bitwidth, engine):
@pytest.mark.parametrize(
"engine",
[
pytest.param(
"cudf_legacy",
marks=pytest.mark.skip(
reason="cannot partially set dtypes for cudf json engine"
),
),
"pandas",
"cudf",
"pandas",
],
)
def test_default_integer_bitwidth_partial(default_integer_bitwidth, engine):
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/utils/ioutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
function or `StringIO`). Multiple inputs may be provided as a list. If a
list is specified each list entry may be of a different input type as long
as each input is of a valid type and all input JSON schema(s) match.
engine : {{ 'auto', 'cudf', 'cudf_legacy', 'pandas' }}, default 'auto'
engine : {{ 'auto', 'cudf', 'pandas' }}, default 'auto'
Parser engine to use. If 'auto' is passed, the engine will be
automatically selected based on the other parameters. See notes below.
orient : string
Expand Down

0 comments on commit 77abf03

Please sign in to comment.