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

[REVIEW] Enable schema_element & keep_quotes support in json reader #11746

Merged
merged 18 commits into from
Sep 27, 2022

Conversation

galipremsagar
Copy link
Contributor

@galipremsagar galipremsagar commented Sep 22, 2022

Description

This PR plumbs schema_element and keep_quotes support in json reader.

Deprecation: This PR also contains changes deprecating dtype as list inputs. This seems to be a very outdated legacy feature we continued to support and cannot be supported with the schema_element.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@galipremsagar galipremsagar added 3 - Ready for Review Ready for review by team Python Affects Python cuDF API. 4 - Needs cuDF (Python) Reviewer labels Sep 22, 2022
@galipremsagar galipremsagar self-assigned this Sep 22, 2022
@galipremsagar galipremsagar requested a review from a team as a code owner September 22, 2022 20:21
@galipremsagar galipremsagar requested a review from vuule September 22, 2022 20:22
@galipremsagar galipremsagar added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function labels Sep 22, 2022
@galipremsagar galipremsagar removed the request for review from wence- September 22, 2022 20:51
@codecov
Copy link

codecov bot commented Sep 22, 2022

Codecov Report

❗ No coverage uploaded for pull request base (branch-22.10@e64c2da). Click here to learn what that means.
Patch has no changes to coverable lines.

❗ Current head abae509 differs from pull request most recent head 3b5bacc. Consider uploading reports for the commit 3b5bacc to get more accurate results

Additional details and impacted files
@@               Coverage Diff               @@
##             branch-22.10   #11746   +/-   ##
===============================================
  Coverage                ?   87.52%           
===============================================
  Files                   ?      133           
  Lines                   ?    21796           
  Branches                ?        0           
===============================================
  Hits                    ?    19076           
  Misses                  ?     2720           
  Partials                ?        0           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines +350 to +352
cu_df = cudf.read_json(
buffer, lines=True, dtype={"0": "bool", "1": "long"}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the dtype argument going to be a breaking change for the engine='cudf' reader?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, dtype is going to continue to work for engine='cudf' reader. But the reason I've deprecated supporting the list of dtypes in dtype param is there is no way we can give the column a name with schema_info being introduced going forward.

Copy link
Contributor Author

@galipremsagar galipremsagar Sep 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dtype=list is going to a breaking change once we drop it. But this PR is just deprecating. Pandas don't have it and hence we won't be needing it either.

Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor issues, but looks good overall

python/cudf/cudf/_lib/json.pyx Show resolved Hide resolved
python/cudf/cudf/io/json.py Outdated Show resolved Hide resolved
python/cudf/cudf/io/json.py Show resolved Hide resolved
python/cudf/cudf/io/json.py Outdated Show resolved Hide resolved
python/cudf/cudf/io/json.py Show resolved Hide resolved
python/cudf/cudf/io/json.py Show resolved Hide resolved
python/cudf/cudf/tests/test_json.py Outdated Show resolved Hide resolved
python/cudf/cudf/utils/ioutils.py Outdated Show resolved Hide resolved
Copy link
Contributor

@karthikeyann karthikeyann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new tests and modified old tests could also use cudf_experimental also as engine.

FutureWarning,
)

if engine in {"cudf", "cudf_experimental"} and not lines:
Copy link
Contributor

@karthikeyann karthikeyann Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With PR #11714, cudf_experimental will support both JSON lines, and also records.
Also, old cudf_experimental already supports records format.

Suggested change
if engine in {"cudf", "cudf_experimental"} and not lines:
if engine == "cudf" and not lines:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karthikeyann, is #11714 ready to merge for 22.10?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if tests pass, it should be. Addressed most of review comments, left some for next PRs.
I merged this PR too locally and tested with above change. Tests pass.
experimental engine could use more python tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n" a valid JSON lines?
This is not supported by cudf_experimental engine. Record orient with lines=True/False is only supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n" a valid JSON lines?

It is:

In [1]: import pandas as pd

In [2]: json = "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n"

In [5]: pd.read_json(json, lines=True, orient="records")
Out[5]: 
   0  1  2
0  1  2  3
1  4  5  6
2  7  8  9

@karthikeyann karthikeyann mentioned this pull request Sep 26, 2022
3 tasks
@galipremsagar galipremsagar requested a review from vuule September 27, 2022 01:23
Copy link
Contributor

@vuule vuule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tests looks more complicated than I'd imagine, but I'm sure there's a web of inter-library bugs that forces us to validate in a roundabout way :)

Comment on lines +765 to +773
dtype={
"a": cudf.StructDtype(
{
"a": cudf.StructDtype({"b": cudf.dtype("int64")}),
"b": cudf.dtype("float64"),
}
),
"b": cudf.ListDtype(cudf.ListDtype("int64")),
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool to see the API in use in a more demanding case.

)

pdf = pd.read_json(
StringIO(expected_json_str), orient="records", lines=True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised we need expected_json_str. Pandas cannot read actual_json_str and enforce the same types as cudf here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, pandas will read them as str/object types. So we would need complex workarounds for that too. Since the test already has a workaround I refrained from adding more workaround code.

Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@galipremsagar galipremsagar added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 3 - Ready for Review Ready for review by team 4 - Needs cuDF (Python) Reviewer labels Sep 27, 2022
@galipremsagar
Copy link
Contributor Author

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 35b0a52 into rapidsai:branch-22.10 Sep 27, 2022
@GregoryKimball GregoryKimball added this to the Nested JSON reader milestone Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge improvement Improvement / enhancement to an existing function non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants