Skip to content

Commit c3274ee

Browse files
SNOW-344567: Added tests for updated pd_writer in snowflake-connector (snowflakedb#347)
1 parent 78e4a73 commit c3274ee

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ ENV/
9797
.tox/
9898
generated_version.py
9999
*coverage.xml
100+
.DS_Store
100101

101102
# Editor specific
102103
.idea/

tests/test_pandas.py

+52-3
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,24 @@ def test_pandas_writeback(engine_testaccount, run_v20_sqlalchemy):
329329
)
330330

331331

332-
@pytest.mark.parametrize("quote_identifiers", [False, True])
333-
def test_pandas_make_pd_writer(engine_testaccount, quote_identifiers):
332+
@pytest.mark.parametrize("chunk_size", [5, 1])
333+
@pytest.mark.parametrize(
334+
"compression",
335+
[
336+
"gzip",
337+
],
338+
)
339+
@pytest.mark.parametrize("parallel", [1, 4])
340+
@pytest.mark.parametrize("quote_identifiers", [True, False])
341+
@pytest.mark.parametrize("auto_create_table", [True, False])
342+
def test_pandas_make_pd_writer(
343+
engine_testaccount,
344+
chunk_size: int,
345+
compression: str,
346+
parallel: int,
347+
quote_identifiers: bool,
348+
auto_create_table: bool,
349+
):
334350
table_name = f"test_table_{uuid.uuid4().hex}".upper()
335351
test_df = pd.DataFrame({"a": range(10), "b": range(10, 20)})
336352

@@ -339,7 +355,13 @@ def write_to_db():
339355
table_name,
340356
engine_testaccount,
341357
index=False,
342-
method=make_pd_writer(quote_identifiers=quote_identifiers),
358+
method=make_pd_writer(
359+
chunk_size=chunk_size,
360+
compression=compression,
361+
parallel=parallel,
362+
quote_identifiers=quote_identifiers,
363+
auto_create_table=auto_create_table,
364+
),
343365
)
344366

345367
with engine_testaccount.connect() as conn:
@@ -362,3 +384,30 @@ def write_to_db():
362384
assert len(results) == 10
363385
finally:
364386
conn.exec_driver_sql(f"DROP TABLE IF EXISTS {table_name}")
387+
388+
389+
def test_pandas_invalid_make_pd_writer(engine_testaccount):
390+
table_name = f"test_table_{uuid.uuid4().hex}".upper()
391+
test_df = pd.DataFrame({"a": range(10), "b": range(10, 20)})
392+
393+
with pytest.raises(
394+
ProgrammingError,
395+
match="Arguments 'table', 'conn', 'keys', and 'data_iter' are not supported parameters for make_pd_writer.",
396+
):
397+
test_df.to_sql(
398+
table_name,
399+
engine_testaccount,
400+
index=False,
401+
method=make_pd_writer(conn=engine_testaccount),
402+
)
403+
404+
with pytest.raises(
405+
ProgrammingError,
406+
match="Arguments 'conn', 'df', 'table_name', and 'schema' are not supported parameters for pd_writer.",
407+
):
408+
test_df.to_sql(
409+
table_name,
410+
engine_testaccount,
411+
index=False,
412+
method=make_pd_writer(df=test_df),
413+
)

0 commit comments

Comments
 (0)