Skip to content

Commit 98dc49f

Browse files
committed
refactor(api)!: align signatures of insert method; name is positional-only; obj is positional-or-keyword; the rest are keyword-only
1 parent 643516a commit 98dc49f

File tree

7 files changed

+52
-48
lines changed

7 files changed

+52
-48
lines changed

ibis/backends/bigquery/__init__.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -718,38 +718,35 @@ def compile(
718718

719719
def insert(
720720
self,
721-
table_name: str,
721+
name: str,
722+
/,
722723
obj: pd.DataFrame | ir.Table | list | dict,
724+
*,
723725
database: str | None = None,
724726
overwrite: bool = False,
725-
):
727+
) -> None:
726728
"""Insert data into a table.
727729
728730
Parameters
729731
----------
730-
table_name
731-
The name of the table to which data needs will be inserted
732+
name
733+
The name of the table to which data needs will be inserted.
732734
obj
733-
The source data or expression to insert
735+
The source data or expression to insert.
734736
database
735737
Name of the attached database that the table is located in.
736738
overwrite
737-
If `True` then replace existing contents of table
738-
739+
If `True` then replace existing contents of table.
739740
"""
740741
table_loc = self._to_sqlglot_table(database)
741742
catalog, db = self._to_catalog_db_tuple(table_loc)
743+
742744
if catalog is None:
743745
catalog = self.current_catalog
744746
if db is None:
745747
db = self.current_database
746748

747-
return super().insert(
748-
table_name,
749-
obj,
750-
database=(catalog, db),
751-
overwrite=overwrite,
752-
)
749+
return super().insert(name, obj, database=(catalog, db), overwrite=overwrite)
753750

754751
def _to_query(
755752
self,

ibis/backends/clickhouse/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,9 @@ def execute(
442442
def insert(
443443
self,
444444
name: str,
445+
/,
445446
obj: pd.DataFrame | ir.Table,
447+
*,
446448
settings: Mapping[str, Any] | None = None,
447449
overwrite: bool = False,
448450
database: str | None = None,

ibis/backends/flink/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,10 @@ def read_json(
904904

905905
def insert(
906906
self,
907-
table_name: str,
907+
name: str,
908+
/,
908909
obj: pa.Table | pd.DataFrame | ir.Table | list | dict,
910+
*,
909911
database: str | None = None,
910912
catalog: str | None = None,
911913
overwrite: bool = False,
@@ -914,7 +916,7 @@ def insert(
914916
915917
Parameters
916918
----------
917-
table_name
919+
name
918920
The name of the table to insert data into.
919921
obj
920922
The source data or expression to insert.
@@ -942,7 +944,7 @@ def insert(
942944

943945
if isinstance(obj, ir.Table):
944946
statement = InsertSelect(
945-
table_name,
947+
name,
946948
self.compile(obj),
947949
database=database,
948950
catalog=catalog,
@@ -951,7 +953,7 @@ def insert(
951953
return self.raw_sql(statement.compile())
952954

953955
identifier = sg.table(
954-
table_name, db=database, catalog=catalog, quoted=self.compiler.quoted
956+
name, db=database, catalog=catalog, quoted=self.compiler.quoted
955957
).sql(self.dialect)
956958

957959
if isinstance(obj, pa.Table):

ibis/backends/impala/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,10 @@ def _wrap_new_table(self, name, database):
720720

721721
def insert(
722722
self,
723-
table_name,
723+
name,
724+
/,
724725
obj=None,
726+
*,
725727
database=None,
726728
overwrite=False,
727729
partition=None,
@@ -731,7 +733,7 @@ def insert(
731733
732734
Parameters
733735
----------
734-
table_name
736+
name
735737
The table name
736738
obj
737739
Table expression or DataFrame
@@ -763,7 +765,7 @@ def insert(
763765
if isinstance(obj, ir.Table):
764766
self._run_pre_execute_hooks(obj)
765767

766-
table = self.table(table_name, database=database)
768+
table = self.table(name, database=database)
767769

768770
if not isinstance(obj, ir.Table):
769771
obj = ibis.memtable(obj)
@@ -782,14 +784,14 @@ def insert(
782784
if set(insert_schema.names) != set(existing_schema.names):
783785
raise com.IbisInputError("Schemas have different names")
784786

785-
for name in insert_schema:
786-
lt = insert_schema[name]
787-
rt = existing_schema[name]
787+
for insert_name in insert_schema:
788+
lt = insert_schema[insert_name]
789+
rt = existing_schema[insert_name]
788790
if not lt.castable(rt):
789791
raise com.IbisInputError(f"Cannot safely cast {lt!r} to {rt!r}")
790792

791793
if partition is not None:
792-
partition_schema = self.get_partition_schema(table_name, database=database)
794+
partition_schema = self.get_partition_schema(name, database=database)
793795
partition_schema_names = frozenset(partition_schema.names)
794796
obj = obj.select(
795797
[
@@ -802,7 +804,7 @@ def insert(
802804
partition_schema = None
803805

804806
statement = ddl.InsertSelect(
805-
self._fully_qualified_name(table_name, database),
807+
self._fully_qualified_name(name, database),
806808
self.compile(obj),
807809
partition=partition,
808810
partition_schema=partition_schema,

ibis/backends/snowflake/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,10 @@ def read_parquet(
11551155

11561156
def insert(
11571157
self,
1158-
table_name: str,
1158+
name: str,
1159+
/,
11591160
obj: pd.DataFrame | ir.Table | list | dict,
1161+
*,
11601162
database: str | None = None,
11611163
overwrite: bool = False,
11621164
) -> None:
@@ -1173,7 +1175,7 @@ def insert(
11731175
11741176
Parameters
11751177
----------
1176-
table_name
1178+
name
11771179
The name of the table to which data needs will be inserted
11781180
obj
11791181
The source data or expression to insert
@@ -1185,7 +1187,6 @@ def insert(
11851187
`("catalog", "database")`.
11861188
overwrite
11871189
If `True` then replace existing contents of table
1188-
11891190
"""
11901191
table_loc = self._to_sqlglot_table(database)
11911192
catalog, db = self._to_catalog_db_tuple(table_loc)
@@ -1196,16 +1197,15 @@ def insert(
11961197
self._run_pre_execute_hooks(obj)
11971198

11981199
query = self._build_insert_from_table(
1199-
target=table_name, source=obj, db=db, catalog=catalog
1200-
)
1201-
table = sg.table(
1202-
table_name, db=db, catalog=catalog, quoted=self.compiler.quoted
1200+
target=name, source=obj, db=db, catalog=catalog
12031201
)
1202+
table = sg.table(name, db=db, catalog=catalog, quoted=self.compiler.quoted)
12041203

1204+
dialect = self.dialect
12051205
statements = []
12061206
if overwrite:
1207-
statements.append(f"TRUNCATE TABLE {table.sql(self.name)}")
1208-
statements.append(query.sql(self.name))
1207+
statements.append(f"TRUNCATE TABLE {table.sql(dialect)}")
1208+
statements.append(query.sql(dialect))
12091209

12101210
statement = ";".join(statements)
12111211
with self._safe_raw_sql(statement):

ibis/backends/sql/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,10 @@ def to_pyarrow_batches(
328328

329329
def insert(
330330
self,
331-
table_name: str,
331+
name: str,
332+
/,
332333
obj: pd.DataFrame | ir.Table | list | dict,
334+
*,
333335
database: str | None = None,
334336
overwrite: bool = False,
335337
) -> None:
@@ -348,7 +350,7 @@ def insert(
348350
349351
Parameters
350352
----------
351-
table_name
353+
name
352354
The name of the table to which data needs will be inserted
353355
obj
354356
The source data or expression to insert
@@ -360,21 +362,20 @@ def insert(
360362
strings like `("catalog", "database")`.
361363
overwrite
362364
If `True` then replace existing contents of table
363-
364365
"""
365366
table_loc = self._to_sqlglot_table(database)
366367
catalog, db = self._to_catalog_db_tuple(table_loc)
367368

368369
if overwrite:
369-
self.truncate_table(table_name, database=(catalog, db))
370+
self.truncate_table(name, database=(catalog, db))
370371

371372
if not isinstance(obj, ir.Table):
372373
obj = ibis.memtable(obj)
373374

374375
self._run_pre_execute_hooks(obj)
375376

376377
query = self._build_insert_from_table(
377-
target=table_name, source=obj, db=db, catalog=catalog
378+
target=name, source=obj, db=db, catalog=catalog
378379
)
379380

380381
with self._safe_raw_sql(query):

ibis/backends/sqlite/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,18 @@ def create_view(
572572

573573
def insert(
574574
self,
575-
table_name: str,
575+
name: str,
576+
/,
576577
obj: pd.DataFrame | ir.Table | list | dict,
578+
*,
577579
database: str | None = None,
578580
overwrite: bool = False,
579581
) -> None:
580582
"""Insert data into a table.
581583
582584
Parameters
583585
----------
584-
table_name
586+
name
585587
The name of the table to which data needs will be inserted
586588
obj
587589
The source data or expression to insert
@@ -596,20 +598,18 @@ def insert(
596598
If inserting data from a different database
597599
ValueError
598600
If the type of `obj` isn't supported
599-
600601
"""
601-
table = sg.table(table_name, catalog=database, quoted=self.compiler.quoted)
602+
table = sg.table(name, catalog=database, quoted=self.compiler.quoted)
602603
if not isinstance(obj, ir.Expr):
603604
obj = ibis.memtable(obj)
604605

605606
self._run_pre_execute_hooks(obj)
606607

607-
query = self._build_insert_from_table(
608-
target=table_name, source=obj, catalog=database
609-
)
610-
insert_stmt = query.sql(self.name)
608+
dialect = self.dialect
609+
query = self._build_insert_from_table(target=name, source=obj, catalog=database)
610+
insert_stmt = query.sql(dialect)
611611

612612
with self.begin() as cur:
613613
if overwrite:
614-
cur.execute(sge.Delete(this=table).sql(self.dialect))
614+
cur.execute(sge.Delete(this=table).sql(dialect))
615615
cur.execute(insert_stmt)

0 commit comments

Comments
 (0)