Skip to content
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

Load Intake Dataset partition or Dask.sample, resolves #290 #291

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ class HoloViewsConverter(object):

_data_options = ['x', 'y', 'kind', 'by', 'use_index', 'use_dask',
'dynamic', 'crs', 'value_label', 'group_label',
'backlog', 'persist', 'sort_date']
'backlog', 'persist', 'sort_date', 'read_partition',
'dask_sample_frac']

_geo_options = ['geo', 'crs', 'project', 'coastline', 'tiles']

Expand Down Expand Up @@ -292,14 +293,16 @@ def __init__(self, data, x, y, kind=None, by=None, use_index=True,
dynspread=False, hover_cols=[], x_sampling=None,
y_sampling=None, project=False, tools=[],
attr_labels=None, coastline=False, tiles=False,
sort_date=True, **kwds):
sort_date=True, read_partition=None, dask_sample_frac=None,
**kwds):

# Process data and related options
self._redim = fields
self.use_index = use_index
self._process_data(kind, data, x, y, by, groupby, row, col,
use_dask, persist, backlog, label, value_label,
hover_cols, attr_labels, kwds)
hover_cols, attr_labels, read_partition, dask_sample_frac,
kwds)

self.value_label = value_label
self.group_label = group_label
Expand Down Expand Up @@ -484,7 +487,7 @@ def _process_crs(self, data, crs):

def _process_data(self, kind, data, x, y, by, groupby, row, col,
use_dask, persist, backlog, label, value_label,
hover_cols, attr_labels, kwds):
hover_cols, attr_labels, read_partition, dask_sample_frac, kwds):
gridded = kind in self._gridded_types
gridded_data = False
da = None
Expand All @@ -495,7 +498,8 @@ def _process_data(self, kind, data, x, y, by, groupby, row, col,
if self.is_series:
data = data.to_frame()
if is_intake(data):
data = process_intake(data, use_dask or persist)
data = process_intake(data, use_dask or persist,
read_partition, dask_sample_frac)

if groupby is not None and not isinstance(groupby, list):
groupby = [groupby]
Expand Down
12 changes: 10 additions & 2 deletions hvplot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,21 @@ def is_xarray(data):
return isinstance(data, (DataArray, Dataset))


def process_intake(data, use_dask):
def process_intake(data, use_dask, read_partition, dask_sample_frac):
if data.container not in ('dataframe', 'xarray'):
raise NotImplementedError('Plotting interface currently only '
'supports DataSource objects declaring '
'a dataframe or xarray container.')
if use_dask:
if read_partition is not None and (dask_sample_frac is not None or use_dask):
raise ValueError("Cannot specify both read_partition"
" and dask_sample_frac or use_dask.")

if dask_sample_frac:
data = data.to_dask().sample(frac=float(dask_sample_frac), replace=True)
elif use_dask:
data = data.to_dask()
elif read_partition:
data = data.read_partition(read_partition)
else:
data = data.read()
return data
Expand Down