title: TypeError: ufunc multiply cannot use operands with types dtype('<M8[ns]') and dtype('float64')
body: <p>I currently have a netCDF file of hourly readings from 18/07/1996 to 31/12/2006 and wish to calculate the JJA seasonal averages of the data variables. I have attempted to follow the example shown on <a href="http://xarray.pydata.org/en/latest/examples/monthly-means.html" rel="nofollow noreferrer">http://xarray.pydata.org/en/latest/examples/monthly-means.html</a>:</p>
  
  <pre><code>ds = xr.open_dataset('BE_Vie.H.nc')
  ds
  
  &gt;&gt; &lt;xarray.Dataset&gt;
  &gt;&gt; Dimensions:      (nt: 2, time: 91632, x: 1, y: 1)
  &gt;&gt; Coordinates:
  &gt;&gt;   * time         (time) datetime64[ns] 1996-07-18T01:00:00 ... 2006-12-31
  &gt;&gt;     latitude     (y, x) float32 ...
  &gt;&gt;     longitude    (y, x) float32 ...
  &gt;&gt; Dimensions without coordinates: nt, x, y
  &gt;&gt; Data variables:
  &gt;&gt;     time_bounds  (time, nt) datetime64[ns] ...
  &gt;&gt;     gpp_gb       (time, y, x) float32 ...
  &gt;&gt;     resp_p_gb    (time, y, x) float32 ...
  &gt;&gt;     resp_s_gb    (time, y, x) float32 ...
  &gt;&gt;     ftl_gb       (time, y, x) float32 ...
  &gt;&gt;     latent_heat  (time, y, x) float32 ...
  &gt;&gt;     rad_net      (time, y, x) float32 ...
  &gt;&gt;     sw_down      (time, y, x) float32 ...
  &gt;&gt;     precip       (time, y, x) float32 ...
  &gt;&gt;     t1p5m_gb     (time, y, x) float32 ...
  &gt;&gt;     q1p5m_gb     (time, y, x) float32 ...
  
  month_length = ds.time.dt.days_in_month
  month_length
  
  &gt;&gt; &lt;xarray.DataArray 'days_in_month' (time: 91632)&gt;
  &gt;&gt; array([31, 31, 31, ..., 31, 31, 31])
  &gt;&gt; Coordinates:
  &gt;&gt;   * time     (time) datetime64[ns] 1996-07-18T01:00:00 ... 2006-12-31
  
  # Calculate the weights by grouping by 'time.season'.
  weights = month_length.groupby('time.season') / month_length.groupby('time.season').sum()
  
  # Test that the sum of the weights for each season is 1.0
  np.testing.assert_allclose(weights.groupby('time.season').sum().values, np.ones(4))
  
  # Calculate the weighted average
  ds_weighted = (ds * weights).groupby('time.season').sum(dim='time')
  </code></pre>
  
  <p>However, I am met by this error:</p>
  
  <pre><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-45-51dd727eba52&gt; in &lt;module&gt;
        6 
        7 # Calculate the weighted average
  ----&gt; 8 ds_weighted = (ds * weights).groupby('time.season').sum(dim='time')
  
  /anaconda3/lib/python3.7/site-packages/xarray/core/dataset.py in func(self, other)
     4774                 self, other = align(self, other, join=align_type, copy=False)
     4775             g = f if not reflexive else lambda x, y: f(y, x)
  -&gt; 4776             ds = self._calculate_binary_op(g, other, join=align_type)
     4777             return ds
     4778 
  
  /anaconda3/lib/python3.7/site-packages/xarray/core/dataset.py in _calculate_binary_op(self, f, other, join, inplace)
     4845         else:
     4846             other_variable = getattr(other, "variable", other)
  -&gt; 4847             new_vars = {k: f(self.variables[k], other_variable) for k in self.data_vars}
     4848         ds._variables.update(new_vars)
     4849         ds._dims = calculate_dimensions(ds._variables)
  
  /anaconda3/lib/python3.7/site-packages/xarray/core/dataset.py in &lt;dictcomp&gt;(.0)
     4845         else:
     4846             other_variable = getattr(other, "variable", other)
  -&gt; 4847             new_vars = {k: f(self.variables[k], other_variable) for k in self.data_vars}
     4848         ds._variables.update(new_vars)
     4849         ds._dims = calculate_dimensions(ds._variables)
  
  /anaconda3/lib/python3.7/site-packages/xarray/core/variable.py in func(self, other)
     1987                 new_data = (
     1988                     f(self_data, other_data)
  -&gt; 1989                     if not reflexive
     1990                     else f(other_data, self_data)
     1991                 )
  
  TypeError: ufunc multiply cannot use operands with types dtype('&lt;M8[ns]') and dtype('float64')
  </code></pre>
  
  <p>How should I convert my time variable in order to make this work? Any help on this problem would be greatly appreciated - thank you!!</p>
  
  <p>More details about the time variable:</p>
  
  <pre><code>ds.time
  
  &gt;&gt; &lt;xarray.DataArray 'time' (time: 91632)&gt;
  &gt;&gt; array(['1996-07-18T01:00:00.000000000', '1996-07-18T02:00:00.000000000',
  &gt;&gt;        '1996-07-18T03:00:00.000000000', ..., '2006-12-30T22:00:00.000000000',
  &gt;&gt;        '2006-12-30T23:00:16.000000000', '2006-12-31T00:00:00.000000000'],
  &gt;&gt;       dtype='datetime64[ns]')
  &gt;&gt; Coordinates:
  &gt;&gt;   * time     (time) datetime64[ns] 1996-07-18T01:00:00 ... 2006-12-31
  &gt;&gt; Attributes:
  &gt;&gt;     standard_name:  time
  &gt;&gt;     long_name:      Time of data
  &gt;&gt;     bounds:         time_bounds
  </code></pre>