home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 458101606

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/2688#issuecomment-458101606 https://api.github.com/repos/pydata/xarray/issues/2688 458101606 MDEyOklzc3VlQ29tbWVudDQ1ODEwMTYwNg== 6628425 2019-01-28T11:50:21Z 2019-01-28T11:50:21Z MEMBER

The issue seems to stem from the fact that the TypeError produced by index.get_value(series, [True, False, True]) is not one of the exceptions that pandas.Series.__getitem__ is written to handle.

In the case of a DatetimeIndex, index.get_value(series, [True, False, True]) raises an InvalidIndexError in place of a TypeError initially raised: ``` In [1]: import xarray as xr; import pandas as pd; import numpy as np

In [2]: times = pd.date_range('2000', periods=3)

In [3]: series = pd.Series([0., np.nan, 1.], index=times)

In [4]: times.get_value(series, [True, False, True])

TypeError Traceback (most recent call last) ~/pandas/pandas/core/indexes/base.py in get_value(self, series, key) 4290 return self._engine.get_value(s, k, -> 4291 tz=getattr(series.dtype, 'tz', None)) 4292 except KeyError as e1:

~/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

~/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

~/pandas/pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

TypeError:

During handling of the above exception, another exception occurred:

InvalidIndexError Traceback (most recent call last) <ipython-input-7-1b8f8313de2a> in <module> ----> 1 times.get_value(series, [True, False, True])

~/pandas/pandas/core/indexes/datetimes.py in get_value(self, series, key) 934 935 try: --> 936 return com.maybe_box(self, Index.get_value(self, series, key), 937 series, key) 938 except KeyError:

~/pandas/pandas/core/indexes/base.py in get_value(self, series, key) 4310 if is_scalar(key): # pragma: no cover 4311 raise IndexError(key) -> 4312 raise InvalidIndexError(key) 4313 4314 def set_value(self, arr, key, value):

InvalidIndexError: [True, False, True] `` This would seem to offer a simple fix for us forCFTimeIndex.get_value(i.e. catch theTypeErrorand raise anInvalidIndexError); however,InvalidIndexErrorunfortunately [is not a public exception](https://github.com/pandas-dev/pandas/blob/master/pandas/errors/__init__.py) in pandas. Raising aKeyErrorinstead happens to work, but I'm not sure if it's safe to rely on that either (because we're sort of at the whim of how it gets handled inSeries.getitem`).

@shoyer do you think you might have a recommendation here? Does either one of those options make sense, or might there be an alternative?

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