Skip to content

TST: Clean up DataFrame.to_csv compression tests #19273

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 5 commits into from
Jan 21, 2018

Conversation

reidy-p
Copy link
Contributor

@reidy-p reidy-p commented Jan 16, 2018

xref #19226

Parametrized some of the compression tests in tests/frame/test_to_csv.py and used the new decompress_file function.

@jreback jreback added the Testing pandas testing functions or related to the test suite label Jan 16, 2018
@jreback jreback added this to the 0.23.0 milestone Jan 17, 2018
for col in df.columns:
assert col in text
@pytest.mark.parametrize('compression', [
None,
Copy link
Contributor

Choose a reason for hiding this comment

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

so if you want to take this one step further, you can make compression a fixture (put it in pandas.tests.conftest) the top-level one, then you can simply use the compression arg and it will just work.

import bz2
f = bz2.BZ2File(filename, 'rb')
# explicitly make sure file is compressed
f = tm.decompress_file(filename, compression)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also change decompress_file to be a contextmanger so you can do

with tm.decompress_file(filename, compress) as fh:
    ......

@reidy-p reidy-p force-pushed the to_csv_df_compress branch from c08fa82 to 6b911c8 Compare January 17, 2018 19:49
@pep8speaks
Copy link

pep8speaks commented Jan 17, 2018

Hello @reidy-p! Thanks for updating the PR.

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

Comment last updated on January 20, 2018 at 11:31 Hours UTC

@reidy-p reidy-p force-pushed the to_csv_df_compress branch from 6b911c8 to 2f44f8a Compare January 17, 2018 19:50
@jreback
Copy link
Contributor

jreback commented Jan 18, 2018

looks very nice. not passing though :< ping on green.

@reidy-p
Copy link
Contributor Author

reidy-p commented Jan 19, 2018

@jreback the failing tests seem to be caused by the following lines of code which have a pytest.mark.parametrize parameter with the name compression which is the same as the new fixture name:

@pytest.mark.network
@pytest.mark.parametrize(
"compression,extension", [
('gzip', '.gz'), ('bz2', '.bz2'), ('zip', '.zip'),
pytest.param('xz', '.xz', marks=td.skip_if_no_lzma)
]
)
@pytest.mark.parametrize('mode', ['explicit', 'infer'])
@pytest.mark.parametrize('engine', ['python', 'c'])
def test_compressed_urls(salaries_table, compression, extension, mode, engine):
check_compressed_urls(salaries_table, compression, extension, mode, engine)

Do you want to try to combine this into the new compression fixture? It could get a bit messy because the compression here differs from the compression covered by the new fixture but I'll see what I can do.

@jreback
Copy link
Contributor

jreback commented Jan 19, 2018

so best would be to fix that
or could just rename the arg for now

@reidy-p reidy-p force-pushed the to_csv_df_compress branch 3 times, most recently from 98d5943 to c499344 Compare January 19, 2018 22:23
@reidy-p reidy-p force-pushed the to_csv_df_compress branch from c499344 to 8077702 Compare January 20, 2018 11:31
@codecov
Copy link

codecov bot commented Jan 20, 2018

Codecov Report

Merging #19273 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #19273   +/-   ##
=======================================
  Coverage   91.53%   91.53%           
=======================================
  Files         150      150           
  Lines       48739    48739           
=======================================
  Hits        44612    44612           
  Misses       4127     4127
Flag Coverage Δ
#multiple 89.9% <100%> (ø) ⬆️
#single 41.73% <50%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/util/testing.py 84.45% <100%> (ø) ⬆️

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 1245f06...8077702. Read the comment docs.

@reidy-p
Copy link
Contributor Author

reidy-p commented Jan 20, 2018

@jreback it’s green now. I just changed the argument name for now but I will continue with cleaning the compression tests.

@jreback jreback merged commit b286789 into pandas-dev:master Jan 21, 2018
@jreback
Copy link
Contributor

jreback commented Jan 21, 2018

thanks @reidy-p keep em coming!

@reidy-p reidy-p deleted the to_csv_df_compress branch January 21, 2018 15:36
@jorisvandenbossche
Copy link
Member

Why does this add a new conftest.py file instead of adding it to the existing one? (which is one level up)

import pandas.util._test_decorators as td


@pytest.fixture(params=[None, 'gzip', 'bz2',
Copy link
Contributor

Choose a reason for hiding this comment

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

@reidy-p yeah move this 1 level high in next PR (it’s already there just add the contents)

@reidy-p
Copy link
Contributor Author

reidy-p commented Jan 22, 2018

Sure. Thanks @jorisvandenbossche

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants