Skip to content

Commit

Permalink
fix(io): add read_parquet and read_csv to base backend mixin
Browse files Browse the repository at this point in the history
xref #5420

This adds `read_parquet` and `read_csv` as methods to the
`FileIOHandler` mixin (renamed from `ResultHandler`).

Now every backend will have these two `read_` methods and will raise a
`NotImplementedError`.

Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
  • Loading branch information
2 people authored and cpcloud committed Feb 3, 2023
1 parent 1dbc682 commit ce80d36
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions ibis/backends/base/__init__.py
Expand Up @@ -214,8 +214,7 @@ def _ipython_key_completions_(self) -> list[str]:
return self._backend.list_tables()


# should have a better name
class ResultHandler:
class _FileIOHandler:
@staticmethod
def _import_pyarrow():
try:
Expand Down Expand Up @@ -322,8 +321,56 @@ def to_pyarrow_batches(
"""
raise NotImplementedError

def read_parquet(
self, path: str | Path, table_name: str | None = None, **kwargs: Any
) -> ir.Table:
"""Register a parquet file as a table in the current backend.
class BaseBackend(abc.ABC, ResultHandler):
Parameters
----------
path
The data source.
table_name
An optional name to use for the created table. This defaults to
a sequentially generated name.
**kwargs
Additional keyword arguments passed to the backend loading function.
Returns
-------
ir.Table
The just-registered table
"""
raise NotImplementedError(
f"{self.name} does not support direct registration of parquet data."
)

def read_csv(
self, path: str | Path, table_name: str | None = None, **kwargs: Any
) -> ir.Table:
"""Register a CSV file as a table in the current backend.
Parameters
----------
path
The data source. A string or Path to the CSV file.
table_name
An optional name to use for the created table. This defaults to
a sequentially generated name.
**kwargs
Additional keyword arguments passed to the backend loading function.
Returns
-------
ir.Table
The just-registered table
"""
raise NotImplementedError(
f"{self.name} does not support direct registration of CSV data."
)


class BaseBackend(abc.ABC, _FileIOHandler):
"""Base backend class.
All Ibis backends must subclass this class and implement all the
Expand Down

0 comments on commit ce80d36

Please sign in to comment.