-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix JSON builder when missing keys in first row #5772
Conversation
The documentation is not available anymore as the PR was closed or merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good ! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
keys = set().union(*[row.keys() for row in dataset]) | ||
mapping = {col: [row.get(col) for row in dataset] for col in keys} | ||
pa_table = pa.Table.from_pydict(mapping) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth noting that Pandas uses Cython to perform this conversion: https://github.com/pandas-dev/pandas/blob/478d340667831908b5b4bf09a2787a11a14560c9/pandas/core/internals/construction.py#L775
I benchmarked the SST datasets converted to a list of dictionaries, and the Pandas version is 26x faster than ours (53.4 ms vs. 1.41s).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the investigation.
Show benchmarksPyArrow==8.0.0 Show updated benchmarks!Benchmark: benchmark_array_xd.json
Benchmark: benchmark_getitem_100B.json
Benchmark: benchmark_indices_mapping.json
Benchmark: benchmark_iterating.json
Benchmark: benchmark_map_filter.json
Show updated benchmarks!Benchmark: benchmark_array_xd.json
Benchmark: benchmark_getitem_100B.json
Benchmark: benchmark_indices_mapping.json
Benchmark: benchmark_iterating.json
Benchmark: benchmark_map_filter.json
|
Until now, the JSON builder only considered the keys present in the first element of the list:
dataset[0].keys()
pa.Table.from_pylist(dataset)
, where "schema (default None): If not passed, will be inferred from the first row of the mapping values"This PR fixes the bug by considering the union of the keys present in all the rows.
Fix #5726.