Repository: pydata/xarray
Issue: to_netcdf ValueError with 0d string variable

```
xray.Dataset( {'password': ([], 'abcd')} ).to_netcdf('/tmp/bar.nc')
```

results in

```
----> 1 xray.Dataset( {'password': ([], 'abcd')} ).to_netcdf('/tmp/bar.nc')

/export/data/envs/popcorn/lib/python2.7/site-packages/xray/core/dataset.pyc in to_netcdf(self, filepath, **kwdargs)
    801         """
    802         with backends.NetCDF4DataStore(filepath, mode='w', **kwdargs) as store:
--> 803             self.dump_to_store(store)
    804 
    805     dump = to_netcdf

/export/data/envs/popcorn/lib/python2.7/site-packages/xray/core/dataset.pyc in dump_to_store(self, store, encoder)
    793         if encoder:
    794             variables, attributes = encoder(variables, attributes)
--> 795         store.store(variables, attributes)
    796         store.sync()
    797 

/export/data/envs/popcorn/lib/python2.7/site-packages/xray/backends/netCDF4_.pyc in store(self, variables, attributes)
    100         # to write times, for example, would fail.
    101         cf_variables, cf_attrs = cf_encoder(variables, attributes)
--> 102         AbstractWritableDataStore.store(self, cf_variables, cf_attrs)
    103 
    104     def open_store_variable(self, var):

/export/data/envs/popcorn/lib/python2.7/site-packages/xray/backends/common.pyc in store(self, variables, attributes)
    153         variables = dict((k, v) for k, v in iteritems(variables)
    154                          if not (k in neccesary_dims and is_trivial_index(v)))
--> 155         self.set_variables(variables)
    156 
    157     def set_dimensions(self, dimensions):

/export/data/envs/popcorn/lib/python2.7/site-packages/xray/backends/common.pyc in set_variables(self, variables)
    165     def set_variables(self, variables):
    166         for vn, v in iteritems(variables):
--> 167             self.set_variable(_encode_variable_name(vn), v)
    168             self.set_necessary_dimensions(v)
    169 

/export/data/envs/popcorn/lib/python2.7/site-packages/xray/backends/netCDF4_.pyc in set_variable(self, name, variable)
    151         attrs = variable.attrs.copy()
    152         if self.format == 'NETCDF4':
--> 153             variable, datatype = _nc4_values_and_dtype(variable)
    154         else:
    155             variable = encode_nc3_variable(variable)

/export/data/envs/popcorn/lib/python2.7/site-packages/xray/backends/netCDF4_.pyc in _nc4_values_and_dtype(var)
     47         # use character arrays instead of unicode, because unicode suppot in
     48         # netCDF4 is still rather buggy
---> 49         data, dims = maybe_convert_to_char_array(var.values, var.dims)
     50         var = Variable(dims, data, var.attrs, var.encoding)
     51         dtype = var.dtype

/export/data/envs/popcorn/lib/python2.7/site-packages/xray/backends/netcdf3.pyc in maybe_convert_to_char_array(data, dims)
     55 def maybe_convert_to_char_array(data, dims):
     56     if data.dtype.kind == 'S' and data.dtype.itemsize > 1:
---> 57         data = conventions.string_to_char(data)
     58         dims = dims + ('string%s' % data.shape[-1],)
     59     return data, dims

/export/data/envs/popcorn/lib/python2.7/site-packages/xray/conventions.pyc in string_to_char(arr)
    344     if kind not in ['U', 'S']:
    345         raise ValueError('argument must be a string')
--> 346     return arr.view(kind + '1').reshape(*[arr.shape + (-1,)])
    347 
    348 

ValueError: new type not compatible with array.
```

Note this does not fail when the 0d value is a number.  This succeeds:

```
xray.Dataset( {'password': ([], 1)} ).to_netcdf('/tmp/bar.nc')
```


Changed files:
xray/test/test_backends.py, xray/conventions.py

diff --git a/xray/conventions.py b/xray/conventions.py
index c1a212d19..4f705b902 100644
--- a/xray/conventions.py
+++ b/xray/conventions.py
@@ -343,7 +343,8 @@ def string_to_char(arr):
     kind = arr.dtype.kind
     if kind not in ['U', 'S']:
         raise ValueError('argument must be a string')
-    return arr.view(kind + '1').reshape(*[arr.shape + (-1,)])
+    # TODO: handle cases where this fails (for non-contiguous arrays?)
+    return arr.reshape(arr.shape + (1,)).view(kind + '1')
 
 
 def char_to_string(arr):
diff --git a/xray/test/test_backends.py b/xray/test/test_backends.py
index 7b959e10d..920902943 100644
--- a/xray/test/test_backends.py
+++ b/xray/test/test_backends.py
@@ -60,8 +60,8 @@ class DatasetIOTestCases(object):
             raise unittest.SkipTest('scipy.io.netcdf is broken on Python 3')
 
         expected = create_test_data()
-        expected['xray_awesomeness'] = ([], np.array(1.e9),
-                                        {'units': 'units of awesome'})
+        expected['float_var'] = ([], 1.0e9, {'units': 'units of awesome'})
+        expected['string_var'] = ([], np.array('foobar', dtype='S'))
         with self.create_store() as store:
             expected.dump_to_store(store)
             # the test data contains times.  In case the store