Repository: pandas-dev/pandas

Issue:
DataFrame.to_parquet raises fails when dataframe is empty
#### Code Sample, a copy-pastable example if possible

```python
import pandas as pd

df = pd.DataFrame()
pd.to_parquet('empty.parquet')
```

#### Problem description

`DataFrame.to_parquet` raises `ValueError: parquet must have string column names` when the dataframe has no columns. `pyarrow` and `fastparquet` both support writing empty dataframes so I don't think this restriction is necessary (see below script).

```py
import fastparquet as fp
import pyarrow as pa
import pyarrow.parquet as pq
import pandas as pd

df = pd.DataFrame()
fn = 'empty.parquet'

# Test fastparquet
fp.write(fn, df)

# Test pyarrow
table = pa.Table.from_pandas(df)
pq.write_table(table, fn)

# This will fail
df.to_parquet(fn)
```

I'm happy to open a PR if it's agreed that this is an issue.

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.7.3.final.0
python-bits: 64
OS: Darwin
OS-release: 18.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.4
scipy: None
pyarrow: 0.14.0
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

</details>



Discussion:
Makes sense to me if you'd like to try a PR

Resolving patch:
diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py
--- a/pandas/io/parquet.py
+++ b/pandas/io/parquet.py
@@ -55,7 +55,7 @@ def validate_dataframe(df):
             raise ValueError("to_parquet only supports IO with DataFrames")
 
         # must have value column names (strings only)
-        if df.columns.inferred_type not in {"string", "unicode"}:
+        if df.columns.inferred_type not in {"string", "unicode", "empty"}:
             raise ValueError("parquet must have string column names")
 
         # index level names must be strings


Test patch:
diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py
--- a/pandas/tests/io/test_parquet.py
+++ b/pandas/tests/io/test_parquet.py
@@ -471,6 +471,11 @@ def test_partition_cols_supported(self, pa, df_full):
             assert len(dataset.partitions.partition_names) == 2
             assert dataset.partitions.partition_names == set(partition_cols)
 
+    def test_empty_dataframe(self, pa):
+        # GH #27339
+        df = pd.DataFrame()
+        check_round_trip(df, pa)
+
 
 class TestParquetFastParquet(Base):
     @td.skip_if_no("fastparquet", min_version="0.2.1")
@@ -566,3 +571,10 @@ def test_error_on_using_partition_cols_and_partition_on(self, fp, df_full):
                     partition_on=partition_cols,
                     partition_cols=partition_cols,
                 )
+
+    def test_empty_dataframe(self, fp):
+        # GH #27339
+        df = pd.DataFrame()
+        expected = df.copy()
+        expected.index.name = "index"
+        check_round_trip(df, fp, expected=expected)