Skip to content

Support creating tables from cudf dataframes #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dask_sql/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self):
RexConverter.add_plugin_class(core.RexLiteralPlugin, replace=False)

InputUtil.add_plugin_class(input_utils.DaskInputPlugin, replace=False)
InputUtil.add_plugin_class(input_utils.PandasInputPlugin, replace=False)
InputUtil.add_plugin_class(input_utils.PandasLikeInputPlugin, replace=False)
InputUtil.add_plugin_class(input_utils.HiveInputPlugin, replace=False)
InputUtil.add_plugin_class(input_utils.IntakeCatalogInputPlugin, replace=False)
InputUtil.add_plugin_class(input_utils.SqlalchemyHiveInputPlugin, replace=False)
Expand Down
4 changes: 2 additions & 2 deletions dask_sql/input_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .hive import HiveInputPlugin
from .intake import IntakeCatalogInputPlugin
from .location import LocationInputPlugin
from .pandas import PandasInputPlugin
from .pandaslike import PandasLikeInputPlugin
from .sqlalchemy import SqlalchemyHiveInputPlugin

__all__ = [
Expand All @@ -13,6 +13,6 @@
HiveInputPlugin,
IntakeCatalogInputPlugin,
LocationInputPlugin,
PandasInputPlugin,
PandasLikeInputPlugin,
SqlalchemyHiveInputPlugin,
]
6 changes: 5 additions & 1 deletion dask_sql/input_utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
dd.DataFrame,
pd.DataFrame,
str,
Union["sqlalchemy.engine.base.Connection", "hive.Cursor"],
Union[
"sqlalchemy.engine.base.Connection",
"hive.Cursor",
"cudf.core.dataframe.DataFrame",
],
]


Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import dask.dataframe as dd
import pandas as pd

try:
import cudf
except ImportError: # pragma: no cover
cudf = None

from dask_sql.input_utils.base import BaseInputPlugin


class PandasInputPlugin(BaseInputPlugin):
"""Input Plugin for Pandas DataFrames, which get converted to dask DataFrames"""
class PandasLikeInputPlugin(BaseInputPlugin):
"""Input Plugin for Pandas Like DataFrames, which get converted to dask DataFrames"""

def is_correct_input(
self, input_item, table_name: str, format: str = None, **kwargs
):
return isinstance(input_item, pd.DataFrame) or format == "dask"
is_cudf_type = cudf and isinstance(input_item, cudf.DataFrame)
return is_cudf_type or isinstance(input_item, pd.DataFrame) or format == "dask"

def to_dc(self, input_item, table_name: str, format: str = None, **kwargs):
npartitions = kwargs.pop("npartitions", 1)
Expand Down