Skip to content

ENH: Make to_csv('filename.csv.zip') compress the output #40387

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

Closed

Conversation

CyberQin
Copy link

@CyberQin CyberQin commented Mar 12, 2021

close old PR,do some work after read pre commit guidelines

@pep8speaks
Copy link

pep8speaks commented Mar 12, 2021

Hello @HQDragon! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-03-16 00:40:58 UTC

@CyberQin
Copy link
Author

CyberQin commented Mar 12, 2021

CI check failed is not caused by changed files, it exist in master branch.
It seems checks failed randomly. commit "582f454“ passed all checks ,commit "a555acd" failed, i only changed imports position between these commits.
How to restart partial checks without new commit

@simonjayhawkins simonjayhawkins added the IO CSV read_csv, to_csv label Mar 14, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

cc @twoertwein if you can have a look

],
)
def test_to_csv_content_name_in_zipped_file(self, df, csv_name):
from pathlib import Path
Copy link
Contributor

Choose a reason for hiding this comment

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

imports go at the top

Copy link
Author

Choose a reason for hiding this comment

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

done in new commit

@jreback
Copy link
Contributor

jreback commented Mar 15, 2021

@HQDragon can you add a whatsnew note also the precommit checks are failing

# ensure_clean will add random str before suffix_zip_name,
# need Path.stem to get real file name
df.to_csv(pth)
zf = ZipFile(pth)
Copy link
Member

Choose a reason for hiding this comment

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

with ZipFile(pth) as zf:
...

Copy link
Author

Choose a reason for hiding this comment

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

done in new commit

@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added the Stale label Apr 16, 2021
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

Thanks @HQDragon, can you merge master and address the comments please? I think this is close to ready.

I guess the CI failure is unrelated, I don't see any docstring change here and that's the failure reason. So, should be fixed when you merge master.

Thanks!

if archive_name is None and isinstance(file, (os.PathLike, str)):
archive_name = os.path.basename(file)
if archive_name.endswith(".zip"):
self.archive_name = archive_name[:-4]
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why to not use pathlib here? This code would look more natural.

df = DataFrame({"ABC": [1]})
with tm.ensure_clean("to_csv_archive_name.zip") as path:
df.to_csv(
path, compression={"method": compression, "archive_name": archive_name}
)
with ZipFile(path) as zp:
expected_arcname = path if archive_name is None else archive_name
if archive_name is None:
Copy link
Member

Choose a reason for hiding this comment

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

why this if and not simply replacing path by Path(path).stem in the original line?

with ZipFile(pth) as zf:
result = zf.filelist[0].filename
expected = pp.stem
assert result == expected
Copy link
Member

Choose a reason for hiding this comment

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

Personal preference would be to simply assert zf.filelist[0].filename == Path(path).stem instead of this incremental approach. I think it's way quicker to read and understand. Also, better to avoid using pp, pth and other cryptic names, descriptive names even if a bit longer make everyone's life easier IMHO.

@datapythonista datapythonista changed the title Enhancement to csv zip compression ENH: Make to_csv('filename.csv.zip') compress the output May 13, 2021
@simonjayhawkins
Copy link
Member

Thanks @HQDragon, can you merge master and address the comments please? I think this is close to ready.

@HQDragon, can you merge master and address the comments please?

@mroeschke
Copy link
Member

Appears that this PR has gone stale thought it's close to ready. Going to close for now but let us know if you'd like to continue working on this and we'd be happy to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO CSV read_csv, to_csv Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DataFrame to_csv compression with 'zip' use zipfilename as archive name
7 participants