Repository: holoviz/hvplot

Issue:
Getting an error on to_dataframe from a basic xarray.hvplot
xarray on latest master: 0.11.0+11.g3ae93ac

```python
import xarray as xr
import hvplot.xarray

ds = xr.tutorial.open_dataset('air_temperature')
ds.hvplot()
```
```python-traceback
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-95a80b7187c4> in <module>()
----> 1 ds.hvplot()

/Users/jsignell/hvplot/hvplot/__init__.py in __call__(self, x, y, kind, **kwds)
     98         HoloViews object: Object representing the requested visualization
     99         """
--> 100         return self._get_converter(x, y, kind, **kwds)(kind, x, y)
    101 
    102     def _get_converter(self, x=None, y=None, kind=None, **kwds):

/Users/jsignell/hvplot/hvplot/__init__.py in _get_converter(self, x, y, kind, **kwds)
    106         kind = kind or params.pop('kind', None)
    107         return HoloViewsConverter(
--> 108             self._data, x, y, kind=kind, **params
    109         )
    110 

/Users/jsignell/hvplot/hvplot/converter.py in __init__(self, data, x, y, kind, by, use_index, group_label, value_label, backlog, persist, use_dask, crs, fields, groupby, dynamic, width, height, shared_axes, grid, legend, rot, title, xlim, ylim, clim, xticks, yticks, logx, logy, loglog, hover, subplots, label, invert, stacked, colorbar, fontsize, colormap, datashade, rasterize, row, col, figsize, debug, xaxis, yaxis, framewise, aggregator, projection, global_extent, geo, precompute, flip_xaxis, flip_yaxis, dynspread, hover_cols, x_sampling, y_sampling, project, xlabel, ylabel, xformatter, yformatter, tools, **kwds)
    150         self._process_data(kind, data, x, y, by, groupby, row, col,
    151                            use_dask, persist, backlog, label, value_label,
--> 152                            hover_cols, kwds)
    153         self.use_index = use_index
    154         self.value_label = value_label

/Users/jsignell/hvplot/hvplot/converter.py in _process_data(self, kind, data, x, y, by, groupby, row, col, use_dask, persist, backlog, label, value_label, hover_cols, kwds)
    372             data, x, y, by_new, groupby_new = process_xarray(data, x, y, by, groupby,
    373                                                              use_dask, persist, gridded,
--> 374                                                              label, value_label)
    375 
    376             if kind not in self._stats_types:

/Users/jsignell/hvplot/hvplot/util.py in process_xarray(data, x, y, by, groupby, use_dask, persist, gridded, label, value_label)
    270             data = data.persist() if persist else data
    271         else:
--> 272             data = dataset.to_dataframe(name=name)
    273             if len(data.index.names) > 1:
    274                 data = data.reset_index()

TypeError: to_dataframe() got an unexpected keyword argument 'name'
```


Discussion:

Resolving patch:
diff --git a/hvplot/util.py b/hvplot/util.py
--- a/hvplot/util.py
+++ b/hvplot/util.py
@@ -237,18 +237,21 @@ def is_geopandas(data):
 
 def process_xarray(data, x, y, by, groupby, use_dask, persist, gridded, label, value_label):
     import xarray as xr
-    dataset = data
-    data_vars = list(dataset.data_vars) if isinstance(data, xr.Dataset) else [data.name]
+    if isinstance(data, xr.Dataset):
+        dataset = data
+    else:
+        name = data.name or label or value_label
+        dataset = data.to_dataset(name=name)
+
+    data_vars = list(dataset.data_vars)
     ignore = (by or []) + (groupby or [])
-    dims = [c for c in data.coords if data[c].shape != () and c not in ignore][::-1]
-    index_dims = [d for d in dims if d in data.indexes]
+    dims = [c for c in dataset.coords if dataset[c].shape != () and c not in ignore][::-1]
+    index_dims = [d for d in dims if d in dataset.indexes]
 
     if gridded:
         data = dataset
-        if data_vars == [None]:
-            label = label or value_label
-            data = data.to_dataset(name=label)
-            data_vars = [label]
+        if len(dims) < 2:
+            dims += [dim for dim in list(data.dims)[::-1] if dim not in dims]
         if not (x or y):
             x, y = index_dims[:2] if len(index_dims) > 1 else dims[:2]
         elif x and not y:
@@ -259,19 +262,15 @@ def process_xarray(data, x, y, by, groupby, use_dask, persist, gridded, label, v
             dims = list(data.coords[x].dims) + list(data.coords[y].dims)
             groupby = [d for d in index_dims if d not in (x, y) and d not in dims]
     else:
-        name = None
-        if not isinstance(dataset, xr.Dataset):
-            name = dataset.name or label or value_label
-            data_vars = [name]
         if use_dask:
-            if not isinstance(dataset, xr.Dataset):
-                dataset = dataset.to_dataset(name=name)
             data = dataset.to_dask_dataframe()
             data = data.persist() if persist else data
         else:
-            data = dataset.to_dataframe(name=name)
+            data = dataset.to_dataframe()
             if len(data.index.names) > 1:
                 data = data.reset_index()
+        if len(dims) == 0:
+            dims = ['index']
         if x and not y:
             y = dims[0] if x in data_vars else data_vars
         elif y and not x:


Test patch:
diff --git a/hvplot/tests/testutil.py b/hvplot/tests/testutil.py
new file mode 100644
--- /dev/null
+++ b/hvplot/tests/testutil.py
@@ -0,0 +1,149 @@
+"""
+Tests  utilities to convert data and projections
+"""
+import numpy as np
+
+from unittest import TestCase, SkipTest
+
+from hvplot.util import process_xarray  # noqa
+
+
+class TestProcessXarray(TestCase):
+
+    def setUp(self):
+        try:
+            import xarray as xr
+            import pandas as pd  # noqa
+        except:
+            raise SkipTest('xarray or pandas not available')
+        self.default_kwargs = {
+            'value_label': 'value',
+            'label': None,
+            'gridded': False,
+            'persist': False,
+            'use_dask': False,
+            'groupby': None,
+            'y': None,
+            'x': None,
+            'by': None
+        }
+        self.ds = xr.tutorial.open_dataset('air_temperature')
+
+    def test_process_1d_xarray_dataarray_with_no_coords(self):
+        import xarray as xr
+        import pandas as pd
+
+        da = xr.DataArray(
+            data=[1, 2, 3])
+
+        data, x, y, by, groupby = process_xarray(data=da, **self.default_kwargs)
+        assert isinstance(data, pd.DataFrame)
+        assert x == 'index'
+        assert y == ['value']
+        assert by == []
+        assert groupby == []
+
+    def test_process_1d_xarray_dataarray_with_coords(self):
+        import xarray as xr
+        import pandas as pd
+
+        da = xr.DataArray(
+            data=[1, 2, 3],
+            coords={'day': [5, 6, 7]},
+            dims=['day'])
+
+        data, x, y, by, groupby = process_xarray(data=da, **self.default_kwargs)
+        assert isinstance(data, pd.DataFrame)
+        assert x == 'day'
+        assert y == ['value']
+        assert by == []
+        assert groupby == []
+
+    def test_process_1d_xarray_dataarray_with_coords_and_name(self):
+        import xarray as xr
+        import pandas as pd
+
+        da = xr.DataArray(
+            data=[1, 2, 3],
+            coords={'day': [5, 6, 7]},
+            dims=['day'],
+            name='temp')
+
+        data, x, y, by, groupby = process_xarray(data=da, **self.default_kwargs)
+        assert isinstance(data, pd.DataFrame)
+        assert x == 'day'
+        assert y == ['temp']
+        assert by == []
+        assert groupby == []
+
+    def test_process_2d_xarray_dataarray_with_no_coords(self):
+        import xarray as xr
+        import pandas as pd
+
+        da = xr.DataArray(np.random.randn(4,5))
+
+        data, x, y, by, groupby = process_xarray(data=da, **self.default_kwargs)
+        assert isinstance(data, pd.DataFrame)
+        assert x == 'index'
+        assert y == ['value']
+        assert by == []
+        assert groupby == []
+
+    def test_process_2d_xarray_dataarray_with_no_coords_as_gridded(self):
+        import xarray as xr
+
+        da = xr.DataArray(np.random.randn(4,5))
+
+        kwargs = self.default_kwargs
+        kwargs.update(gridded=True)
+
+        data, x, y, by, groupby = process_xarray(data=da, **kwargs)
+        assert isinstance(data, xr.Dataset)
+        assert list(data.data_vars.keys()) == ['value']
+        assert x == 'dim_1'
+        assert y == 'dim_0'
+        assert by is None
+        assert groupby is None
+
+    def test_process_2d_xarray_dataarray_with_coords_as_gridded(self):
+        import xarray as xr
+
+        da = xr.DataArray(
+            data=np.random.randn(4,5),
+            coords={'y': [3, 4, 5, 6, 7]},
+            dims=['x', 'y'])
+
+        kwargs = self.default_kwargs
+        kwargs.update(gridded=True)
+
+        data, x, y, by, groupby = process_xarray(data=da, **kwargs)
+        assert isinstance(data, xr.Dataset)
+        assert list(data.data_vars.keys()) == ['value']
+        assert x == 'y'
+        assert y == 'x'
+        assert by is None
+        assert groupby is None
+
+    def test_process_3d_xarray_dataset_with_coords(self):
+        import pandas as pd
+
+        data, x, y, by, groupby = process_xarray(data=self.ds, **self.default_kwargs)
+        assert isinstance(data, pd.DataFrame)
+        assert x == 'time'
+        assert y == ['air']
+        assert by == []
+        assert groupby == ['lon', 'lat']
+
+    def test_process_3d_xarray_dataset_with_coords_as_gridded(self):
+        import xarray as xr
+
+        kwargs = self.default_kwargs
+        kwargs.update(gridded=True, x='lon', y='lat')
+
+        data, x, y, by, groupby = process_xarray(data=self.ds, **kwargs)
+        assert isinstance(data, xr.Dataset)
+        assert list(data.data_vars.keys()) == ['air']
+        assert x == 'lon'
+        assert y == 'lat'
+        assert by is None
+        assert groupby == ['time']