Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions python/pyarrow/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,14 @@ def write_table(table, where, row_group_size=None, version='1.0',
""".format(_parquet_writer_arg_docs)


def _mkdir_if_not_exists(fs, path):
if fs._isfilestore() and not fs.exists(path):
try:
fs.mkdir(path)
except OSError:
assert fs.exists(path)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be worth adding exist_ok to the filesystem interface. Python has this kwarg for os.makedirs (but not os.mkdir) to say not to error if the directory already exists (defaults to False).

Copy link
Member

Choose a reason for hiding this comment

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

Before adding more things to the interface, I would prefer that we continue to settle the discussion on a uniform file interface between dask, Arrow and others. Then we actually know to what we all want to converge to.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe worth opening a JIRA about this in either case



def write_to_dataset(table, root_path, partition_cols=None,
filesystem=None, preserve_index=True, **kwargs):
"""
Expand Down Expand Up @@ -1012,11 +1020,7 @@ def write_to_dataset(table, root_path, partition_cols=None,
else:
fs = _ensure_filesystem(filesystem)

if fs._isfilestore() and not fs.exists(root_path):
try:
fs.mkdir(root_path)
except OSError:
assert fs.exists(root_path)
_mkdir_if_not_exists(fs, root_path)

if partition_cols is not None and len(partition_cols) > 0:
df = table.to_pandas()
Expand All @@ -1034,8 +1038,7 @@ def write_to_dataset(table, root_path, partition_cols=None,
subtable = Table.from_pandas(subgroup,
preserve_index=preserve_index)
prefix = "/".join([root_path, subdir])
if fs._isfilestore() and not fs.exists(prefix):
fs.mkdir(prefix)
_mkdir_if_not_exists(fs, prefix)
outfile = compat.guid() + ".parquet"
full_path = "/".join([prefix, outfile])
with fs.open(full_path, 'wb') as f:
Expand Down