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

feat: Add ignore_nulls option to struct.json_encode #17867

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nikhilramolla
Copy link

@nikhilramolla nikhilramolla commented Jul 25, 2024

Feature issue: #17865

Adding an option to ignore null values inside a struct when performing json_encode.

@nikhilramolla nikhilramolla changed the title feat: add ignore_nulls option to struct.json_encode feat: Add ignore_nulls option to struct.json_encode Jul 25, 2024
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Jul 25, 2024
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.

Project coverage is 80.56%. Comparing base (3016c07) to head (045b7f6).
Report is 338 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-json/src/json/write/serialize.rs 88.23% 2 Missing ⚠️
crates/polars-json/src/json/write/mod.rs 0.00% 1 Missing ⚠️
...rates/polars-plan/src/dsl/function_expr/struct_.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17867      +/-   ##
==========================================
+ Coverage   80.47%   80.56%   +0.08%     
==========================================
  Files        1505     1495      -10     
  Lines      197273   197025     -248     
  Branches     2807     2813       +6     
==========================================
- Hits       158764   158727      -37     
+ Misses      37987    37777     -210     
+ Partials      522      521       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tim-stephenson
Copy link
Contributor

Any updates on this? I was working on adding json_encode to the root namespace (so everything can be json_encode-able). In doing so I wanted to think about adding the ignore_nulls option, and how to add it to all the arrow types (not just struct). Is there a better method to accomplish this than adding it to all the functions in crates/polars-json/src/json/write/serialize.rs?

@nikhilramolla
Copy link
Author

@tim-stephenson since the json serialization at crates/polars-json/src/json/write/serialize.rs is handwritten, the ignore_nulls option had to be added to skip wherever needed.

Moving json_encode to the root namespace would be way better. We could use iterators which can optionally skip null values, and serialize with serde.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants