-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Enhancement dataframe to csv use zip method #39662
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
Enhancement dataframe to csv use zip method #39662
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this breaks some tests
=========================== short test summary info ============================
FAILED pandas/tests/io/formats/test_to_csv.py::TestToCSV::test_to_csv_zip_arguments[None-zip]
FAILED pandas/tests/io/formats/test_to_csv.py::TestToCSV::test_to_csv_zip_arguments[None-infer]
@@ -726,6 +726,12 @@ def __init__( | |||
self.archive_name = archive_name | |||
self.multiple_write_buffer: Optional[Union[StringIO, BytesIO]] = None | |||
|
|||
# add csv file name like gz or bz2 | |||
if archive_name is None and isinstance(file, (os.PathLike, str)): | |||
archive_name = os.path.basename(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably better to replace os.path.basename
with stringify_path
(to handle PathLike objects). That might also fix the failing test_to_csv_compression_encoding_gcs
test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, you probably still need basename
to avoid having the entire path within the archive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert to os.path.basename
, but start get different ci errors, does my commit affect it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a small test case. For example, write a compressed CSV file and then open it with zipfile.ZipFile to check the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test case and finish pre commit, a new PR is opened #40387
…rame_to_csv_use_zip_method
合并mainstream
… expected to be 'xxxx.cvs'
Hello @HQDragon! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-03-11 07:51:12 UTC |
… expected to be 'xxxx.cvs'
…_zip_method' into enhancement_dataframe_to_csv_use_zip_method # Conflicts: # pandas/tests/frame/methods/test_to_csv.py
… expected to be 'xxxx.cvs'
…_zip_method' into enhancement_dataframe_to_csv_use_zip_method # Conflicts: # pandas/tests/frame/methods/test_to_csv.py
Enhancement dataframe to csv use zip method,now df.to_csv('myfile.csv.zip') works like df.to_csv('myfile.csv.gz'), generate a zip file with a myfile.csv as content
test code