-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Infer compression from non-string paths #17206
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
Changes from 1 commit
ec0a292
64d55c0
5272b9e
e3d4d9a
8fcf398
0f925c1
8a15074
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,21 @@ def test_read_csv_infer_compression(self): | |
|
||
inputs[3].close() | ||
|
||
def test_read_csv_infer_compression_pathlib(self): | ||
""" | ||
Test that compression is inferred from pathlib.Path paths. | ||
""" | ||
try: | ||
import pathlib | ||
except ImportError: | ||
pytest.skip('need pathlib to run') | ||
expected = self.read_csv(self.csv1, index_col=0, parse_dates=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Construct the expected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how to do that... I followed the method used by other tests in this module, e.g. |
||
for extension in '', '.gz', '.bz2': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use the |
||
path = pathlib.Path(self.csv1 + extension) | ||
df = self.read_csv( | ||
path, index_col=0, parse_dates=True, compression='infer') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this test entirely. instead add a generalized compression test (iow for all extensions & path types) in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback, Just to make sure we're on the same page. All path types would be:
All compression types would be None, xz, bz2, zip, and gzip. But in all cases, we'd be inferring compression? Just want to make sure the scope of this test should be primarily |
||
tm.assert_frame_equal(expected, df) | ||
|
||
def test_invalid_compression(self): | ||
msg = 'Unrecognized compression type: sfark' | ||
with tm.assert_raises_regex(ValueError, msg): | ||
|
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.
Does this test pass on
master
(or are you going to make changes so that it will) ?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.
As of a3b9ee9, this test should fail when
pathlib
is available and be skipped otherwise.Once I commit the enhancement, this test should pass when
pathlib
is available and be skipped otherwise.Uh oh!
There was an error while loading. Please reload this page.
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.
What's your plan for the fix? We do have the
__fspath__
stuff now. It's possible we could just ensure that the path has been stringified before doing the compression inference.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.
@TomAugspurger see b4e280f. The fix should be simple I think, just passing
filepath_or_buffer
through the_stringify_path
function in_infer_compression
.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.
Yep, perfect (the fspath stuff happens inside
_stringify_path
). Let's hope that works.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.
Separately, let's take advantage of
pytest.importorskip
functionality here instead of doing thistry-except
block.