Skip to content

Commit 681378c

Browse files
committed
refactor(api)!: align signatures of read_csv method; sources are positional-only, everything else is required-keyword
1 parent 63d44e6 commit 681378c

File tree

10 files changed

+34
-29
lines changed

10 files changed

+34
-29
lines changed

ibis/backends/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def read_parquet(
368368
)
369369

370370
def read_csv(
371-
self, path: str | Path, table_name: str | None = None, **kwargs: Any
371+
self, path: str | Path, /, *, table_name: str | None = None, **kwargs: Any
372372
) -> ir.Table:
373373
"""Register a CSV file as a table in the current backend.
374374
@@ -386,7 +386,6 @@ def read_csv(
386386
-------
387387
ir.Table
388388
The just-registered table
389-
390389
"""
391390
raise NotImplementedError(
392391
f"{self.name} does not support direct registration of CSV data."

ibis/backends/bigquery/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def read_parquet(
270270
)
271271

272272
def read_csv(
273-
self, path: str | Path, table_name: str | None = None, **kwargs: Any
273+
self, path: str | Path, /, *, table_name: str | None = None, **kwargs: Any
274274
) -> ir.Table:
275275
"""Read CSV data into a BigQuery table.
276276
@@ -288,7 +288,6 @@ def read_csv(
288288
-------
289289
Table
290290
An Ibis table expression
291-
292291
"""
293292
job_config = bq.LoadJobConfig(
294293
source_format=bq.SourceFormat.CSV,

ibis/backends/clickhouse/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ def read_parquet(
611611
def read_csv(
612612
self,
613613
path: str | Path,
614+
/,
615+
*,
614616
table_name: str | None = None,
615617
engine: str = "MergeTree",
616618
**kwargs: Any,

ibis/backends/datafusion/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,17 @@ def _register_in_memory_table(self, op: ops.InMemoryTable) -> None:
394394

395395
def read_csv(
396396
self,
397-
source_list: str | Path | list[str | Path] | tuple[str | Path],
397+
paths: str | Path | list[str | Path] | tuple[str | Path],
398+
/,
399+
*,
398400
table_name: str | None = None,
399401
**kwargs: Any,
400402
) -> ir.Table:
401403
"""Register a CSV file as a table in the current database.
402404
403405
Parameters
404406
----------
405-
source_list
407+
paths
406408
The data source. A string or Path to the CSV file.
407409
table_name
408410
An optional name to use for the created table. This defaults to
@@ -414,9 +416,8 @@ def read_csv(
414416
-------
415417
ir.Table
416418
The just-registered table
417-
418419
"""
419-
path = normalize_filenames(source_list)
420+
path = normalize_filenames(paths)
420421
table_name = table_name or gen_name("read_csv")
421422
# Our other backends support overwriting views / tables when re-registering
422423
self.con.deregister_table(table_name)

ibis/backends/duckdb/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,9 @@ def read_json(
567567

568568
def read_csv(
569569
self,
570-
source_list: str | list[str] | tuple[str],
570+
paths: str | list[str] | tuple[str],
571+
/,
572+
*,
571573
table_name: str | None = None,
572574
columns: Mapping[str, str | dt.DataType] | None = None,
573575
types: Mapping[str, str | dt.DataType] | None = None,
@@ -577,7 +579,7 @@ def read_csv(
577579
578580
Parameters
579581
----------
580-
source_list
582+
paths
581583
The data source(s). May be a path to a file or directory of CSV
582584
files, or an iterable of CSV files.
583585
table_name
@@ -644,17 +646,14 @@ def read_csv(
644646
│ 2.0 │ 3.0 │ <POINT (2 3)> │
645647
└─────────┴─────────┴──────────────────────┘
646648
"""
647-
source_list = util.normalize_filenames(source_list)
649+
paths = util.normalize_filenames(paths)
648650

649651
if not table_name:
650652
table_name = util.gen_name("read_csv")
651653

652654
# auto_detect and columns collide, so we set auto_detect=True
653655
# unless COLUMNS has been specified
654-
if any(
655-
source.startswith(("http://", "https://", "s3://"))
656-
for source in source_list
657-
):
656+
if any(source.startswith(("http://", "https://", "s3://")) for source in paths):
658657
self._load_extensions(["httpfs"])
659658

660659
kwargs.setdefault("header", True)
@@ -694,7 +693,7 @@ def make_struct_argument(obj: Mapping[str, str | dt.DataType]) -> sge.Struct:
694693

695694
self._create_temp_view(
696695
table_name,
697-
sg.select(STAR).from_(self.compiler.f.read_csv(source_list, *options)),
696+
sg.select(STAR).from_(self.compiler.f.read_csv(paths, *options)),
698697
)
699698

700699
return self.table(table_name)

ibis/backends/flink/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,8 @@ def read_parquet(
846846
def read_csv(
847847
self,
848848
path: str | Path,
849+
/,
850+
*,
849851
schema: sch.Schema | None = None,
850852
table_name: str | None = None,
851853
) -> ir.Table:

ibis/backends/polars/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def sql(
127127
def read_csv(
128128
self,
129129
path: str | Path | list[str | Path] | tuple[str | Path],
130+
/,
131+
*,
130132
table_name: str | None = None,
131133
**kwargs: Any,
132134
) -> ir.Table:
@@ -148,7 +150,6 @@ def read_csv(
148150
-------
149151
ir.Table
150152
The just-registered table
151-
152153
"""
153154
source_list = normalize_filenames(path)
154155
# Flatten the list if there's only one element because Polars

ibis/backends/pyspark/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -832,15 +832,17 @@ def read_parquet(
832832

833833
def read_csv(
834834
self,
835-
source_list: str | list[str] | tuple[str],
835+
paths: str | list[str] | tuple[str],
836+
/,
837+
*,
836838
table_name: str | None = None,
837839
**kwargs: Any,
838840
) -> ir.Table:
839841
"""Register a CSV file as a table in the current database.
840842
841843
Parameters
842844
----------
843-
source_list
845+
paths
844846
The data source(s). May be a path to a file or directory of CSV files, or an
845847
iterable of CSV files.
846848
table_name
@@ -854,7 +856,6 @@ def read_csv(
854856
-------
855857
ir.Table
856858
The just-registered table
857-
858859
"""
859860
if self.mode == "streaming":
860861
raise NotImplementedError(
@@ -863,9 +864,9 @@ def read_csv(
863864
)
864865
inferSchema = kwargs.pop("inferSchema", True)
865866
header = kwargs.pop("header", True)
866-
source_list = util.normalize_filenames(source_list)
867+
paths = util.normalize_filenames(paths)
867868
spark_df = self._session.read.csv(
868-
source_list, inferSchema=inferSchema, header=header, **kwargs
869+
paths, inferSchema=inferSchema, header=header, **kwargs
869870
)
870871
table_name = table_name or util.gen_name("read_csv")
871872

@@ -1116,6 +1117,8 @@ def to_kafka(
11161117
def read_csv_dir(
11171118
self,
11181119
path: str | Path,
1120+
/,
1121+
*,
11191122
table_name: str | None = None,
11201123
watermark: Watermark | None = None,
11211124
**kwargs: Any,
@@ -1139,7 +1142,6 @@ def read_csv_dir(
11391142
-------
11401143
ir.Table
11411144
The just-registered table
1142-
11431145
"""
11441146
inferSchema = kwargs.pop("inferSchema", True)
11451147
header = kwargs.pop("header", True)

ibis/backends/snowflake/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def create_table(
859859
return self.table(name, database=(catalog, db))
860860

861861
def read_csv(
862-
self, path: str | Path, table_name: str | None = None, **kwargs: Any
862+
self, path: str | Path, /, *, table_name: str | None = None, **kwargs: Any
863863
) -> ir.Table:
864864
"""Register a CSV file as a table in the Snowflake backend.
865865
@@ -877,7 +877,6 @@ def read_csv(
877877
-------
878878
Table
879879
The table that was read from the CSV file
880-
881880
"""
882881
stage = ibis.util.gen_name("stage")
883882
file_format = ibis.util.gen_name("format")

ibis/expr/api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,9 @@ def row_number() -> ir.IntegerColumn:
14811481

14821482

14831483
def read_csv(
1484-
sources: str | Path | Sequence[str | Path],
1484+
paths: str | Path | Sequence[str | Path],
1485+
/,
1486+
*,
14851487
table_name: str | None = None,
14861488
**kwargs: Any,
14871489
) -> ir.Table:
@@ -1492,7 +1494,7 @@ def read_csv(
14921494
14931495
Parameters
14941496
----------
1495-
sources
1497+
paths
14961498
A filesystem path or URL or list of same. Supports CSV and TSV files.
14971499
table_name
14981500
A name to refer to the table. If not provided, a name will be generated.
@@ -1529,12 +1531,11 @@ def read_csv(
15291531
│ 2 │ NULL │
15301532
│ NULL │ f │
15311533
└───────┴────────┘
1532-
15331534
"""
15341535
from ibis.config import _default_backend
15351536

15361537
con = _default_backend()
1537-
return con.read_csv(sources, table_name=table_name, **kwargs)
1538+
return con.read_csv(paths, table_name=table_name, **kwargs)
15381539

15391540

15401541
@experimental

0 commit comments

Comments
 (0)