@@ -292,13 +292,14 @@ def write_pandas(
292
292
293
293
294
294
def make_pd_writer (
295
- quote_identifiers : bool = True ,
295
+ ** kwargs ,
296
296
) -> Callable [
297
297
[
298
298
pandas .io .sql .SQLTable ,
299
299
sqlalchemy .engine .Engine | sqlalchemy .engine .Connection ,
300
300
Iterable ,
301
301
Iterable ,
302
+ Any ,
302
303
],
303
304
None ,
304
305
]:
@@ -311,24 +312,28 @@ def make_pd_writer(
311
312
sf_connector_version_df = pd.DataFrame([('snowflake-connector-python', '1.0')], columns=['NAME', 'NEWEST_VERSION'])
312
313
sf_connector_version_df.to_sql('driver_versions', engine, index=False, method=make_pd_writer())
313
314
314
- # to use quote_identifiers=False,
315
+ # to use parallel=1, quote_identifiers=False,
315
316
from functools import partial
316
317
sf_connector_version_df.to_sql(
317
- 'driver_versions', engine, index=False, method=make_pd_writer(quote_identifiers=False)))
318
+ 'driver_versions', engine, index=False, method=make_pd_writer(parallel=1, quote_identifiers=False)))
318
319
319
- Args:
320
- quote_identifiers: if True (default), the pd_writer will pass quote identifiers to Snowflake.
321
- If False, the created pd_writer will not quote identifiers (and typically coerced to uppercase by Snowflake)
320
+ This function takes arguments used by 'pd_writer' (excluding 'table', 'conn', 'keys', and 'data_iter')
321
+ Please refer to 'pd_writer' for documentation.
322
322
"""
323
- return partial (pd_writer , quote_identifiers = quote_identifiers )
323
+ if any (arg in kwargs for arg in ("table" , "conn" , "keys" , "data_iter" )):
324
+ raise ProgrammingError (
325
+ "Arguments 'table', 'conn', 'keys', and 'data_iter' are not supported parameters for make_pd_writer."
326
+ )
327
+
328
+ return partial (pd_writer , ** kwargs )
324
329
325
330
326
331
def pd_writer (
327
332
table : pandas .io .sql .SQLTable ,
328
333
conn : sqlalchemy .engine .Engine | sqlalchemy .engine .Connection ,
329
334
keys : Iterable ,
330
335
data_iter : Iterable ,
331
- quote_identifiers : bool = True ,
336
+ ** kwargs ,
332
337
) -> None :
333
338
"""This is a wrapper on top of write_pandas to make it compatible with to_sql method in pandas.
334
339
@@ -339,16 +344,20 @@ def pd_writer(
339
344
sf_connector_version_df = pd.DataFrame([('snowflake-connector-python', '1.0')], columns=['NAME', 'NEWEST_VERSION'])
340
345
sf_connector_version_df.to_sql('driver_versions', engine, index=False, method=pd_writer)
341
346
342
- # to use quote_identifiers=False, see `make_pd_writer`
343
-
344
347
Args:
345
348
table: Pandas package's table object.
346
349
conn: SQLAlchemy engine object to talk to Snowflake.
347
350
keys: Column names that we are trying to insert.
348
351
data_iter: Iterator over the rows.
349
- quote_identifiers: if True (default), quote identifiers passed to Snowflake. If False, identifiers are not
350
- quoted (and typically coerced to uppercase by Snowflake)
352
+
353
+ More parameters can be provided to be used by 'write_pandas' (excluding 'conn', 'df', 'table_name', and 'schema'),
354
+ Please refer to 'write_pandas' for documentation on other available parameters.
351
355
"""
356
+ if any (arg in kwargs for arg in ("conn" , "df" , "table_name" , "schema" )):
357
+ raise ProgrammingError (
358
+ "Arguments 'conn', 'df', 'table_name', and 'schema' are not supported parameters for pd_writer."
359
+ )
360
+
352
361
sf_connection = conn .connection .connection
353
362
df = pandas .DataFrame (data_iter , columns = keys )
354
363
write_pandas (
@@ -357,5 +366,5 @@ def pd_writer(
357
366
# Note: Our sqlalchemy connector creates tables case insensitively
358
367
table_name = table .name .upper (),
359
368
schema = table .schema ,
360
- quote_identifiers = quote_identifiers ,
369
+ ** kwargs ,
361
370
)
0 commit comments