home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 693120404

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/4363#issuecomment-693120404 https://api.github.com/repos/pydata/xarray/issues/4363 693120404 MDEyOklzc3VlQ29tbWVudDY5MzEyMDQwNA== 1217238 2020-09-16T01:47:13Z 2020-09-16T01:47:13Z MEMBER

This doesn't work in pandas either: ``` In [8]: x.to_series().loc[dt.date(2010, 1, 1)]


KeyError Traceback (most recent call last) <ipython-input-8-148c4a8380fa> in <module> ----> 1 x.to_series().loc[dt.date(2010, 1, 1)]

~/miniconda3/envs/xarray-py38/lib/python3.8/site-packages/pandas/core/indexing.py in getitem(self, key) 877 878 maybe_callable = com.apply_if_callable(key, self.obj) --> 879 return self._getitem_axis(maybe_callable, axis=axis) 880 881 def _is_scalar_access(self, key: Tuple):

~/miniconda3/envs/xarray-py38/lib/python3.8/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis) 1108 # fall thru to straight lookup 1109 self._validate_key(key, axis) -> 1110 return self._get_label(key, axis=axis) 1111 1112 def _get_slice_axis(self, slice_obj: slice, axis: int):

~/miniconda3/envs/xarray-py38/lib/python3.8/site-packages/pandas/core/indexing.py in _get_label(self, label, axis) 1057 def _get_label(self, label, axis: int): 1058 # GH#5667 this will fail if the label is not present in the axis. -> 1059 return self.obj.xs(label, axis=axis) 1060 1061 def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):

~/miniconda3/envs/xarray-py38/lib/python3.8/site-packages/pandas/core/generic.py in xs(self, key, axis, level, drop_level) 3480 loc, new_index = self.index.get_loc_level(key, drop_level=drop_level) 3481 else: -> 3482 loc = self.index.get_loc(key) 3483 3484 if isinstance(loc, np.ndarray):

~/miniconda3/envs/xarray-py38/lib/python3.8/site-packages/pandas/core/indexes/datetimes.py in get_loc(self, key, method, tolerance) 620 else: 621 # unrecognized type --> 622 raise KeyError(key) 623 624 try:

KeyError: datetime.date(2010, 1, 1) ```

I think it is reasonable to expect a date object to work like a date string, but I would suggest fixing this in pandas first (inside DatetimeIndex.get_loc), at which point it should automatically work for xarray.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  683657289
Powered by Datasette · Queries took 2.777ms · About: xarray-datasette