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

ENH: Add tranparent compression to json reading/writing #17798

Merged
merged 6 commits into from
Oct 6, 2017

Conversation

simongibbons
Copy link
Contributor

@simongibbons simongibbons commented Oct 5, 2017

This works in the same way as the argument to read_csvand to_csv.

I've added tests confirming that it works with both file paths, and S3 URLs. (obviously there will be edge cases I've missed - please let me know if there are important ones that I should add coverage for).

The implementation is mostly plumbing, using the logic that was in place for the same functionality in read_csv.

@pep8speaks
Copy link

pep8speaks commented Oct 5, 2017

Hello @simongibbons! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on October 06, 2017 at 08:18 Hours UTC

This works in the same way as the argument to ``read_csv``
and ``to_csv``.

I've added tests confirming that it works with both file
paths, as well and file URLs and S3 URLs.
@codecov
Copy link

codecov bot commented Oct 5, 2017

Codecov Report

Merging #17798 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17798      +/-   ##
==========================================
- Coverage   91.24%   91.24%   -0.01%     
==========================================
  Files         163      163              
  Lines       49967    49967              
==========================================
- Hits        45593    45590       -3     
- Misses       4374     4377       +3
Flag Coverage Δ
#multiple 89.04% <ø> (+0.01%) ⬆️
#single 40.24% <ø> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/io/json/json.py 100% <ø> (ø) ⬆️
pandas/core/generic.py 92.03% <ø> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.74% <0%> (-0.1%) ⬇️
pandas/core/indexes/datetimes.py 95.48% <0%> (-0.1%) ⬇️
pandas/io/common.py 71.61% <0%> (+2.96%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22515f5...3ed830c. Read the comment docs.

@codecov
Copy link

codecov bot commented Oct 5, 2017

Codecov Report

Merging #17798 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17798      +/-   ##
==========================================
- Coverage   91.24%   91.23%   -0.02%     
==========================================
  Files         163      163              
  Lines       49967    49971       +4     
==========================================
- Hits        45593    45590       -3     
- Misses       4374     4381       +7
Flag Coverage Δ
#multiple 89.03% <ø> (ø) ⬆️
#single 40.24% <ø> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 92.03% <ø> (ø) ⬆️
pandas/io/json/json.py 100% <ø> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.74% <0%> (-0.1%) ⬇️
pandas/core/indexes/timedeltas.py 91.19% <0%> (ø) ⬆️
pandas/core/indexes/range.py 92.83% <0%> (ø) ⬆️
pandas/core/indexes/numeric.py 97.18% <0%> (ø) ⬆️
pandas/core/indexes/period.py 92.78% <0%> (ø) ⬆️
pandas/core/indexes/datetimes.py 95.58% <0%> (ø) ⬆️
pandas/core/indexes/multi.py 96.39% <0%> (ø) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22515f5...402fa11. Read the comment docs.

COMPRESSION_TYPES = [None, 'bz2', 'gzip', 'xz']


def test_compress_gzip():
Copy link
Contributor

Choose a reason for hiding this comment

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

pls parametrize all of this

see how this is done in other compression tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the pattern that was used in the tests of compression with pickle.

Where there is a function which is used to decompress files by compression type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The zip tests will IMO always need to be special cases, as there isn't a writer we will always need to read from a fixture.

@@ -195,7 +195,7 @@ Other Enhancements
- :func:`read_json` now accepts a ``chunksize`` parameter that can be used when ``lines=True``. If ``chunksize`` is passed, read_json now returns an iterator which reads in ``chunksize`` lines with each iteration. (:issue:`17048`)
- :meth:`DataFrame.assign` will preserve the original order of ``**kwargs`` for Python 3.6+ users instead of sorting the column names
- Improved the import time of pandas by about 2.25x (:issue:`16764`)

- :func:`read_json` and :func:`to_json` now accept a ``compression`` argument which allows them to transparently handled compressed files. (:issue:`XXXXXXX`)
Copy link
Contributor

Choose a reason for hiding this comment

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

update this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@jreback jreback added Enhancement IO JSON read_json, to_json, json_normalize labels Oct 6, 2017
@jreback jreback added this to the 0.21.0 milestone Oct 6, 2017
@jreback
Copy link
Contributor

jreback commented Oct 6, 2017

lgtm, thanks for the quick response!

@TomAugspurger ?

@simongibbons
Copy link
Contributor Author

Let me know if you want me to squash this when it's ready to merge.

@jreback
Copy link
Contributor

jreback commented Oct 6, 2017

@simongibbons no need to squash, its done automatically on merging.

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

+1.

Does the ZIP file need to be added to MANIFEST.IN?



@pytest.mark.parametrize('compression', COMPRESSION_TYPES)
def test_with_s3_url(compression):
Copy link
Contributor

Choose a reason for hiding this comment

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

This shares some code with the (to be merged) #17201

I think it's fine for now, but we'll want to clean it up whenever the later is merged. Since this is clean at the moment, I think we'll merge it, and then refactor this test in #17201.

@jreback
Copy link
Contributor

jreback commented Oct 6, 2017

Does the ZIP file need to be added to MANIFEST.IN?

hmm I think it might be need to be added to setup.py

https://travis-ci.org/pandas-dev/pandas/jobs/284093329 is our build test, which IS picking this up.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Oct 6, 2017

Probably covered by pandas.tests.io: ['json/data/*.json'] in the setup.py.

@TomAugspurger TomAugspurger merged commit 3b4121b into pandas-dev:master Oct 6, 2017
@TomAugspurger
Copy link
Contributor

Thanks @simongibbons!

@jreback
Copy link
Contributor

jreback commented Oct 6, 2017

@TomAugspurger NO its NOT covered by that. See the failing tests. This NEEDS to be in setup.py

@jreback
Copy link
Contributor

jreback commented Oct 6, 2017

you can change it to '/json/data/*.json*' and it will work I think

jreback added a commit to jreback/pandas that referenced this pull request Oct 6, 2017
jreback added a commit that referenced this pull request Oct 6, 2017
ghost pushed a commit to reef-technologies/pandas that referenced this pull request Oct 16, 2017
…7798)

* ENH: Add tranparent compression to json reading/writing

This works in the same way as the argument to ``read_csv``
and ``to_csv``.

I've added tests confirming that it works with both file
paths, as well and file URLs and S3 URLs.

* Fix PEP8 violations

* Add PR number to whatsnew entry

* Remove problematic Windows test (The S3 test hits the same edge case)

* Extract decompress file function so that pytest.paramatrize can be used cleanly

* Fix typo in whatsnew entry
ghost pushed a commit to reef-technologies/pandas that referenced this pull request Oct 16, 2017
alanbato pushed a commit to alanbato/pandas that referenced this pull request Nov 10, 2017
…7798)

* ENH: Add tranparent compression to json reading/writing

This works in the same way as the argument to ``read_csv``
and ``to_csv``.

I've added tests confirming that it works with both file
paths, as well and file URLs and S3 URLs.

* Fix PEP8 violations

* Add PR number to whatsnew entry

* Remove problematic Windows test (The S3 test hits the same edge case)

* Extract decompress file function so that pytest.paramatrize can be used cleanly

* Fix typo in whatsnew entry
alanbato pushed a commit to alanbato/pandas that referenced this pull request Nov 10, 2017
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
…7798)

* ENH: Add tranparent compression to json reading/writing

This works in the same way as the argument to ``read_csv``
and ``to_csv``.

I've added tests confirming that it works with both file
paths, as well and file URLs and S3 URLs.

* Fix PEP8 violations

* Add PR number to whatsnew entry

* Remove problematic Windows test (The S3 test hits the same edge case)

* Extract decompress file function so that pytest.paramatrize can be used cleanly

* Fix typo in whatsnew entry
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: add gzip/bz2 compression to relevant read_* methods
4 participants