[Python] saving a dataframe to the same partitioned location silently doubles the data
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
When a user saves a dataframe:
```python
df1.to_parquet('/tmp/table', partition_cols=['col_a'], engine='pyarrow')
```
it will create sub-directories named "`a=val1`", "`a=val2`" in `/tmp/table`. Each of them will contain one (or more?) parquet files with random filenames.
If a user runs the same command again, the code will use the existing sub-directories, but with different (random) filenames. As a result, any data loaded from this folder will be wrong - each row will be present twice.
For example, when using
```python
df1.to_parquet('/tmp/table', partition_cols=['col_a'], engine='pyarrow') # second time
df2 = pd.read_parquet('/tmp/table', engine='pyarrow')
assert len(df1) == len(df2) # raise an error
```
This is a subtle change in the data that can pass unnoticed.
I would expect that the code will prevent the user from using an non-empty destination as partitioned target. an overwrite flag can also be useful.
**Reporter**: [Tsvika Shapira](https://issues.apache.org/jira/browse/ARROW-7706)
#### Related issues:
- [[C++][Python][R][Dataset] Control overwriting vs appending when writing to existing dataset](https://github.com/apache/arrow/issues/28157) (is related to)
**Note**: *This issue was originally created as [ARROW-7706](https://issues.apache.org/jira/browse/ARROW-7706). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Assessment
This issue has not been assessed yet.