cmip6-temperature-demo icon indicating copy to clipboard operation
cmip6-temperature-demo copied to clipboard

ValueError: Replacing the dayofyr or dayofwk of a datetime is not supported.

Open mktippett opened this issue 5 years ago • 0 comments

Thanks for this great tutorial! When I try to run it I get this error.

ds = ds.sel(time=time_slice) # subset the data for the time period of interest

gives

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-33-d56499b6e04f> in <module>
     12 
     13 
---> 14     ds = ds.sel(time=time_slice) # subset the data for the time period of interest
     15 
     16     # drop redundant variables (like "height: 2m")

~/miniconda3/envs/pangeo/lib/python3.6/site-packages/xarray/core/dataset.py in sel(self, indexers, method, tolerance, drop, **indexers_kwargs)
   1998         indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "sel")
   1999         pos_indexers, new_indexes = remap_label_indexers(
-> 2000             self, indexers=indexers, method=method, tolerance=tolerance
   2001         )
   2002         result = self.isel(indexers=pos_indexers, drop=drop)

~/miniconda3/envs/pangeo/lib/python3.6/site-packages/xarray/core/coordinates.py in remap_label_indexers(obj, indexers, method, tolerance, **indexers_kwargs)
    390 
    391     pos_indexers, new_indexes = indexing.remap_label_indexers(
--> 392         obj, v_indexers, method=method, tolerance=tolerance
    393     )
    394     # attach indexer's coordinate to pos_indexers

~/miniconda3/envs/pangeo/lib/python3.6/site-packages/xarray/core/indexing.py in remap_label_indexers(data_obj, indexers, method, tolerance)
    259             coords_dtype = data_obj.coords[dim].dtype
    260             label = maybe_cast_to_coords_dtype(label, coords_dtype)
--> 261             idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance)
    262             pos_indexers[dim] = idxr
    263             if new_idx is not None:

~/miniconda3/envs/pangeo/lib/python3.6/site-packages/xarray/core/indexing.py in convert_label_indexer(index, label, index_name, method, tolerance)
    123             _sanitize_slice_element(label.start),
    124             _sanitize_slice_element(label.stop),
--> 125             _sanitize_slice_element(label.step),
    126         )
    127         if not isinstance(indexer, slice):

~/miniconda3/envs/pangeo/lib/python3.6/site-packages/pandas/core/indexes/base.py in slice_indexer(self, start, end, step, kind)
   5032         slice(1, 3)
   5033         """
-> 5034         start_slice, end_slice = self.slice_locs(start, end, step=step, kind=kind)
   5035 
   5036         # return a slice

~/miniconda3/envs/pangeo/lib/python3.6/site-packages/pandas/core/indexes/base.py in slice_locs(self, start, end, step, kind)
   5246         start_slice = None
   5247         if start is not None:
-> 5248             start_slice = self.get_slice_bound(start, "left", kind)
   5249         if start_slice is None:
   5250             start_slice = 0

~/miniconda3/envs/pangeo/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_slice_bound(self, label, side, kind)
   5158         # For datetime indices label may be a string that has to be converted
   5159         # to datetime boundary according to its resolution.
-> 5160         label = self._maybe_cast_slice_bound(label, side, kind)
   5161 
   5162         # we need to look up the label

~/miniconda3/envs/pangeo/lib/python3.6/site-packages/xarray/coding/cftimeindex.py in _maybe_cast_slice_bound(self, label, side, kind)
    336         pandas.tseries.index.DatetimeIndex._maybe_cast_slice_bound"""
    337         if isinstance(label, str):
--> 338             parsed, resolution = _parse_iso8601_with_reso(self.date_type, label)
    339             start, end = _parsed_string_to_bounds(self.date_type, resolution, parsed)
    340             if self.is_monotonic_decreasing and len(self) > 1:

~/miniconda3/envs/pangeo/lib/python3.6/site-packages/xarray/coding/cftimeindex.py in _parse_iso8601_with_reso(date_type, timestr)
    114     # 1.0.3.4.
    115     replace["dayofwk"] = -1
--> 116     return default.replace(**replace), resolution
    117 
    118 

cftime/_cftime.pyx in cftime._cftime.datetime.replace()

ValueError: Replacing the dayofyr or dayofwk of a datetime is not supported.

mktippett avatar Dec 09 '19 23:12 mktippett