title: How to save xarray.DataArray with complex128 data to netcdf
body: <p>I have some complex data (numpy dtype complex128) in an xarray data set which I want to save with to_netcdf. I get the following error: </p>
  
  <pre><code>TypeError: illegal primitive data type, must be one of dict_keys(['S1', 'i1', 'u1', 'i2', 'u2', 'i4', 'u4', 'i8', 'u8', 'f4', 'f8']), got complex128
  </code></pre>
  
  <p>I do understand that I am passing a data type to the underlying netCDF4 which is not supported. I also found <a href="https://unidata.github.io/netcdf4-python/" rel="nofollow noreferrer">https://unidata.github.io/netcdf4-python/</a> on compound data types with netcdf4. But unfortunately I don't see how I can apply that to my problem as I am not directly working with the netcdf4 library.</p>
  
  <p>Can I save data of the data type complex128 to netcdf while keeping the data type (using <code>xarray.DataArray.to_netcdf</code>)?</p>
  
  <p>MWE:</p>
  
  <pre><code>import numpy as np
  import xarray as xr
  complex = [np.complex(1.0, 1.0), np.complex(2.0, 1.0), np.complex(3.0, 1.0), np.complex(4.0, 1.0)]
  data = xr.DataArray(complex)
  data.to_netcdf(r'test.nc')
  </code></pre>