-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pathlib.Path in io #16292
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
BUG: pathlib.Path in io #16292
Changes from 3 commits
cff750f
adf77f0
ae22641
086a11b
3dda8bc
1ecbe0d
8a4e291
9293b14
83415a7
577796e
f135e32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,6 +314,8 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None, | |
|
||
handles = list() | ||
f = path_or_buf | ||
# Convert pathlib.Path/py.path.local or string | ||
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. can you add a blank line |
||
path_or_buf = _stringify_path(path_or_buf) | ||
is_path = isinstance(path_or_buf, compat.string_types) | ||
|
||
if compression: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -679,6 +679,18 @@ def test_file(self): | |
|
||
tm.assert_frame_equal(url_table, local_table) | ||
|
||
def test_path_pathlib(self): | ||
df = tm.makeDataFrame() | ||
result = tm.round_trip_pathlib(df.to_csv, | ||
lambda p: self.read_csv(p, index_col=0)) | ||
tm.assert_frame_equal(df, result) | ||
|
||
def test_pickle_path_localpath(self): | ||
df = tm.makeDataFrame() | ||
result = tm.round_trip_pathlib(df.to_csv, | ||
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. round_trip_localpath ? |
||
lambda p: self.read_csv(p, index_col=0)) | ||
tm.assert_frame_equal(df, result) | ||
|
||
def test_nonexistent_path(self): | ||
# gh-2428: pls no segfault | ||
# gh-14086: raise more helpful FileNotFoundError | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,26 @@ def test_from_iterator(self): | |
tm.assert_frame_equal(df, df0.iloc[2:5, :]) | ||
rdr.close() | ||
|
||
def test_path_pathlib(self): | ||
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. looks like needs xfailing here |
||
tm._skip_if_no_pathlib() | ||
from pathlib import Path | ||
for j in 0, 1: | ||
df0 = self.data[j] | ||
for k in self.test_ix[j]: | ||
fname = Path(os.path.join(self.dirpath, "test%d.sas7bdat" % k)) | ||
df = pd.read_sas(fname, encoding='utf-8') | ||
tm.assert_frame_equal(df, df0) | ||
|
||
def test_path_localpath(self): | ||
tm._skip_if_no_localpath() | ||
from py.path import local as LocalPath | ||
for j in 0, 1: | ||
df0 = self.data[j] | ||
for k in self.test_ix[j]: | ||
fname = LocalPath(os.path.join(self.dirpath, "test%d.sas7bdat" % k)) | ||
df = pd.read_sas(fname, encoding='utf-8') | ||
tm.assert_frame_equal(df, df0) | ||
|
||
def test_iterator_loop(self): | ||
# github #13654 | ||
for j in 0, 1: | ||
|
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.
localpath too?