Skip to content

ENH: Added append functionality for DataFrame.to_json #48540

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

Merged
merged 27 commits into from
Oct 20, 2022

Conversation

SFuller4
Copy link
Contributor

@SFuller4 SFuller4 commented Sep 14, 2022

Added new a new keyword argument (mode) to DataFrame.to_json(). Strictly only takes 'w' and 'a' as inputs, defaulting to 'w'. mode='a' is only supported when lines is True and orient is 'records'. This enhancement only effects to_json when a path_or_buf is supplied, otherwise it returns the json dump like expected, however, checks will occur when mode='a' regardless of whether path_or_buf is supplied.

@mroeschke mroeschke added the IO JSON read_json, to_json, json_normalize label Sep 14, 2022
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Oct 16, 2022
@SFuller4
Copy link
Contributor Author

@mroeschke Is there anything that I need to do for this PR? or are we just waiting for the right time to merge it in?

@mroeschke
Copy link
Member

@mroeschke Is there anything that I need to do for this PR? or are we just waiting for the right time to merge it in?

Looks like this needs a rebase and there are still typing errors: https://github.com/pandas-dev/pandas/actions/runs/3057060394/jobs/4931831550

@SFuller4 SFuller4 reopened this Oct 18, 2022
@SFuller4
Copy link
Contributor Author

@mroeschke I'm still unsure about this typing issue that it's failing. Could you help me out with that? Also, I realize I need to adjust which whatsnew file i'm changing so just let me know which one I need to add it to and I'll do that. Not sure why 1.6.0 is showing as a completely new file on my commit...

@mroeschke
Copy link
Member

The overloads in pandas/io/json/_json.py need to be adjusted for mode.

Yeah the v1.6.0.rst was renamed to v2.0.0.rst so the 2.0 version should be added

@SFuller4
Copy link
Contributor Author

@mroeschke Looks like that fixed the docstring issue. Now I'm just unsure of what whatsnew to put the enhancement information in.

@mroeschke
Copy link
Member

Now I'm just unsure of what whatsnew to put the enhancement information in.

You can put it in v2.0.0.rst

@SFuller4
Copy link
Contributor Author

@mroeschke Finished. Let me know if there's anything else that I need to do.

@mroeschke mroeschke removed the Stale label Oct 20, 2022
@mroeschke mroeschke added this to the 2.0 milestone Oct 20, 2022
@mroeschke mroeschke merged commit 7a8d165 into pandas-dev:main Oct 20, 2022
@mroeschke
Copy link
Member

Thanks for sticking with this @SFuller4!

@SFuller4
Copy link
Contributor Author

Thanks for the assistance @mroeschke! Next time should be smoother haha

phofl pushed a commit to phofl/pandas that referenced this pull request Oct 21, 2022
* Adding functionality for mode='a' when saving DataFrame.to_json. Only supported when lines=True and orient='records'.

* Adding tests for append functionality, along with updated whatsnew, user_guide, and generic docstring.

* pre-commit adjustments

* Update pandas/io/json/_json.py

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

* Fixing pytest cases per request from mroeschke. Switching whatsnew version per request from mroeschke.

* removed repr() from ValueError msg

* fixing bad formatting

* Adjusting Typing from str to Literal["a", "w"] per request.

* updating typing issues in the core file

* Adding functionality for mode='a' when saving DataFrame.to_json. Only supported when lines=True and orient='records'.

* Adding tests for append functionality, along with updated whatsnew, user_guide, and generic docstring.

* pre-commit adjustments

* Update pandas/io/json/_json.py

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

* fixing typing issues by adding mode to the overloads of to_json. Also removing whatsnew 1.6.0

* moving enhancement information to whatsnew/v2.0.0

* removing extra space from old whatsnew

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
* Adding functionality for mode='a' when saving DataFrame.to_json. Only supported when lines=True and orient='records'.

* Adding tests for append functionality, along with updated whatsnew, user_guide, and generic docstring.

* pre-commit adjustments

* Update pandas/io/json/_json.py

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

* Fixing pytest cases per request from mroeschke. Switching whatsnew version per request from mroeschke.

* removed repr() from ValueError msg

* fixing bad formatting

* Adjusting Typing from str to Literal["a", "w"] per request.

* updating typing issues in the core file

* Adding functionality for mode='a' when saving DataFrame.to_json. Only supported when lines=True and orient='records'.

* Adding tests for append functionality, along with updated whatsnew, user_guide, and generic docstring.

* pre-commit adjustments

* Update pandas/io/json/_json.py

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

* fixing typing issues by adding mode to the overloads of to_json. Also removing whatsnew 1.6.0

* moving enhancement information to whatsnew/v2.0.0

* removing extra space from old whatsnew

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Enable append mode to JSON lines
2 participants