Skip to content

Commit 56999c9

Browse files
committed
Add test for Parquet GCS write
1 parent 8974b50 commit 56999c9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/io/test_gcs.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
from contextlib import contextmanager
13
from io import StringIO
24

35
import numpy as np
@@ -60,6 +62,31 @@ def open(*args):
6062
assert_frame_equal(df1, df2)
6163

6264

65+
@td.skip_if_no("gcsfs")
66+
def test_to_parquet_gcs_new_file(monkeypatch, tmpdir):
67+
"""Regression test for writing to a not-yet-existent GCS Parquet file."""
68+
df1 = DataFrame(
69+
{
70+
"int": [1, 3],
71+
"float": [2.0, np.nan],
72+
"str": ["t", "s"],
73+
"dt": date_range("2018-06-18", periods=2),
74+
}
75+
)
76+
77+
class MockGCSFileSystem:
78+
@contextmanager
79+
def open(self, path, mode='r', *args):
80+
if 'w' not in mode:
81+
raise FileNotFoundError
82+
with open(os.path.join(tmpdir, 'test.parquet'), mode) as f:
83+
yield f
84+
85+
monkeypatch.setattr("gcsfs.GCSFileSystem", MockGCSFileSystem)
86+
df1.to_parquet("gs://test/test.csv", index=True, engine='fastparquet',
87+
compression=None)
88+
89+
6390
@td.skip_if_no("gcsfs")
6491
def test_gcs_get_filepath_or_buffer(monkeypatch):
6592
df1 = DataFrame(

0 commit comments

Comments
 (0)