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

Remove legacy JSON reader from Python #15538

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading