Skip to content

Commit

Permalink
Optimized cuDF interface (#4436)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored May 25, 2020
1 parent ebe00fe commit c0138a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
23 changes: 12 additions & 11 deletions holoviews/core/data/cudf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def init(cls, eltype, data, kdims, vdims):
data, _, _ = PandasInterface.init(eltype, data, kdims, vdims)
data = cudf.from_pandas(data)

ncols = len(data.columns)
columns = list(data.columns)
ncols = len(columns)
index_names = [data.index.name]
if index_names == [None]:
index_names = ['index']
Expand All @@ -80,21 +81,21 @@ def init(cls, eltype, data, kdims, vdims):
ndim = None
nvdim = vdim_param.bounds[1] if isinstance(vdim_param.bounds[1], int) else None
if kdims and vdims is None:
vdims = [c for c in data.columns if c not in kdims]
vdims = [c for c in columns if c not in kdims]
elif vdims and kdims is None:
kdims = [c for c in data.columns if c not in vdims][:ndim]
kdims = [c for c in columns if c not in vdims][:ndim]
elif kdims is None:
kdims = list(data.columns[:ndim])
kdims = list(columns[:ndim])
if vdims is None:
vdims = [d for d in data.columns[ndim:((ndim+nvdim) if nvdim else None)]
vdims = [d for d in columns[ndim:((ndim+nvdim) if nvdim else None)]
if d not in kdims]
elif kdims == [] and vdims is None:
vdims = list(data.columns[:nvdim if nvdim else None])
vdims = list(columns[:nvdim if nvdim else None])

# Handle reset of index if kdims reference index by name
for kd in kdims:
kd = dimension_name(kd)
if kd in data.columns:
if kd in columns:
continue
if any(kd == ('index' if name is None else name)
for name in index_names):
Expand All @@ -106,13 +107,13 @@ def init(cls, eltype, data, kdims, vdims):

if kdims:
kdim = dimension_name(kdims[0])
if eltype._auto_indexable_1d and ncols == 1 and kdim not in data.columns:
if eltype._auto_indexable_1d and ncols == 1 and kdim not in columns:
data = data.copy()
data.insert(0, kdim, np.arange(len(data)))

for d in kdims+vdims:
d = dimension_name(d)
if len([c for c in data.columns if c == d]) > 1:
if len([c for c in columns if c == d]) > 1:
raise DataError('Dimensions may not reference duplicated DataFrame '
'columns (found duplicate %r columns). If you want to plot '
'a column against itself simply declare two dimensions '
Expand All @@ -136,12 +137,12 @@ def values(cls, dataset, dim, expanded=True, flat=True, compute=True,
data = dataset.data[dim.name]
if not expanded:
data = data.unique()
return data.to_array() if compute else data
return data.to_array() if compute else data.values
elif keep_index:
return data
elif compute:
return data.to_array()
return data
return data.values


@classmethod
Expand Down
3 changes: 2 additions & 1 deletion holoviews/core/data/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def isscalar(cls, dataset, dim):
def validate(cls, dataset, vdims=True):
dim_types = 'all' if vdims else 'key'
dimensions = dataset.dimensions(dim_types, label='name')
not_found = [d for d in dimensions if d not in dataset.data.columns]
cols = list(dataset.data.columns)
not_found = [d for d in dimensions if d not in cols]
if not_found:
raise DataError("Supplied data does not contain specified "
"dimensions, the following dimensions were "
Expand Down

0 comments on commit c0138a8

Please sign in to comment.