Skip to content

Commit

Permalink
[BUG] Fix cudf.pandas integration issues with cuxfilter (#619)
Browse files Browse the repository at this point in the history
THis PR makes sure that the proxy objects returned/used by cudf.pandas work with cuxfilter.

closes #605

Authors:
  - Matthew Murray (https://github.com/Matt711)
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - Ajay Thorve (https://github.com/AjayThorve)

URL: #619
  • Loading branch information
Matt711 authored Aug 16, 2024
1 parent a00bf9d commit cc18207
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
5 changes: 4 additions & 1 deletion python/cuxfilter/charts/bokeh/plots/bar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import holoviews as hv
import param
import pandas as pd
from cuxfilter.charts.core.aggregate import BaseAggregateChart
from cuxfilter.assets.numba_kernels import calc_groupby
import panel as pn
Expand All @@ -10,7 +11,9 @@ class InteractiveBar(param.Parameterized):
x = param.String("x", doc="x axis column name")
y = param.List(["y"], doc="y axis column names as a list")
source_df = param.ClassSelector(
class_=cudf.DataFrame, default=cudf.DataFrame(), doc="source dataframe"
class_=(cudf.DataFrame, pd.DataFrame),
default=cudf.DataFrame(),
doc="source dataframe",
)
box_stream = param.ClassSelector(
class_=hv.streams.SelectionXY, default=hv.streams.SelectionXY()
Expand Down
9 changes: 7 additions & 2 deletions python/cuxfilter/charts/core/core_chart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cudf
import pandas as pd
import dask_cudf
import logging
import panel as pn
Expand Down Expand Up @@ -61,15 +62,19 @@ def library_specific_params(self):
def x_dtype(self):
if isinstance(self.source, ColumnDataSource):
return self.source.data[self.data_x_axis].dtype
elif isinstance(self.source, (cudf.DataFrame, dask_cudf.DataFrame)):
elif isinstance(
self.source, (cudf.DataFrame, dask_cudf.DataFrame, pd.DataFrame)
):
return self.source[self.x].dtype
return None

@property
def y_dtype(self):
if isinstance(self.source, ColumnDataSource):
return self.source.data[self.data_x_axis].dtype
elif isinstance(self.source, (cudf.DataFrame, dask_cudf.DataFrame)):
elif isinstance(
self.source, (cudf.DataFrame, dask_cudf.DataFrame, pd.DataFrame)
):
return self.source[self.y].dtype
return None

Expand Down
9 changes: 7 additions & 2 deletions python/cuxfilter/charts/core/non_aggregate/core_graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Tuple
import cudf
import pandas as pd
import dask.dataframe as dd
import dask_cudf
import panel as pn
Expand Down Expand Up @@ -169,13 +170,17 @@ def __init__(

@property
def x_dtype(self):
if isinstance(self.nodes, (cudf.DataFrame, dask_cudf.DataFrame)):
if isinstance(
self.nodes, (cudf.DataFrame, dask_cudf.DataFrame, pd.DataFrame)
):
return self.nodes[self.node_x].dtype
return None

@property
def y_dtype(self):
if isinstance(self.nodes, (cudf.DataFrame, dask_cudf.DataFrame)):
if isinstance(
self.nodes, (cudf.DataFrame, dask_cudf.DataFrame, pd.DataFrame)
):
return self.nodes[self.node_y].dtype
return None

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cudf
import pandas as pd
import dask_cudf
from typing import Tuple
import panel as pn
Expand Down Expand Up @@ -30,7 +31,9 @@ def y_dtype(self):
overwriting the y_dtype property from BaseChart for stackedLines where
self.y is a list of columns
"""
if isinstance(self.source, (cudf.DataFrame, dask_cudf.DataFrame)):
if isinstance(
self.source, (cudf.DataFrame, dask_cudf.DataFrame, pd.DataFrame)
):
return self.source[self.y[0]].dtype
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import requests
from PIL import Image
from io import BytesIO
import pandas as pd


def load_image(url):
Expand Down Expand Up @@ -180,7 +181,7 @@ def add_reset_event(self, callback_fn):

class InteractiveDatashader(InteractiveDatashaderBase):
source_df = param.ClassSelector(
class_=(cudf.DataFrame, dask_cudf.DataFrame),
class_=(cudf.DataFrame, dask_cudf.DataFrame, pd.DataFrame),
doc="source cuDF/dask_cuDF dataframe",
)
x = param.String("x")
Expand Down Expand Up @@ -498,11 +499,11 @@ def view(self):

class InteractiveDatashaderGraph(InteractiveDatashaderBase):
nodes_df = param.ClassSelector(
class_=(cudf.DataFrame, dask_cudf.DataFrame),
class_=(cudf.DataFrame, dask_cudf.DataFrame, pd.DataFrame),
doc="nodes cuDF/dask_cuDF dataframe",
)
edges_df = param.ClassSelector(
class_=(cudf.DataFrame, dask_cudf.DataFrame),
class_=(cudf.DataFrame, dask_cudf.DataFrame, pd.DataFrame),
doc="edges cuDF/dask_cuDF dataframe",
)
node_x = param.String("x")
Expand Down
3 changes: 2 additions & 1 deletion python/cuxfilter/charts/datashader/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import dask.dataframe as dd
import cupy as cp
import cudf
import pandas as pd
import holoviews as hv
from bokeh import events
from PIL import Image
Expand Down Expand Up @@ -145,7 +146,7 @@ def format_source_data(self, dataframe):
Ouput:
"""
if isinstance(dataframe, cudf.DataFrame):
if isinstance(dataframe, (cudf.DataFrame, pd.DataFrame)):
self.nodes = dataframe
else:
self.nodes = dataframe.data
Expand Down
5 changes: 4 additions & 1 deletion python/cuxfilter/charts/panel_widgets/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ...assets.cudf_utils import get_min_max
from bokeh.models import ColumnDataSource
import cudf
import pandas as pd
import dask_cudf
import panel as pn
import uuid
Expand Down Expand Up @@ -88,7 +89,9 @@ class DateRangeSlider(BaseWidget):
def x_dtype(self):
if isinstance(self.source, ColumnDataSource):
return self.source.data[self.data_x_axis].dtype
elif isinstance(self.source, (cudf.DataFrame, dask_cudf.DataFrame)):
elif isinstance(
self.source, (cudf.DataFrame, dask_cudf.DataFrame, pd.DataFrame)
):
return self.source[self.x].dtype
return None

Expand Down

0 comments on commit cc18207

Please sign in to comment.