home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 926855056

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/5815#issuecomment-926855056 https://api.github.com/repos/pydata/xarray/issues/5815 926855056 IC_kwDOAMm_X843Pq-Q 4160723 2021-09-24T19:00:36Z 2021-09-24T19:00:36Z MEMBER

This is the behavior that we get when directly indexing the pandas.DatetimeIndex:

```python

idx = xa_orig.get_index('time') idx DatetimeIndex(['2013-01-01', '2013-02-01', '2013-03-01', '2013-04-01', '2013-05-01', '2013-06-01', '2013-07-01', '2013-08-01', '2013-09-01', '2013-10-01'], dtype='datetime64[ns]', name='time', freq='MS') idx[0:2] # slice of ints -> preserve freq DatetimeIndex(['2013-01-01', '2013-02-01'], dtype='datetime64[ns]', name='time', freq='MS') idx[[0, 1]] # list of ints -> drop freq DatetimeIndex(['2013-01-01', '2013-02-01'], dtype='datetime64[ns]', name='time', freq=None) ```

I think that this behavior makes sense since indexing the index with an arbitrary list of integer positions may not yield labels with a meaningful, unique frequency. With a slice it can be updated easily (pandas does it), e.g.,

```python

idx[0:2:4] DatetimeIndex(['2013-01-01'], dtype='datetime64[ns]', name='time', freq='4MS') ```

Not sure what's happening with the copy of the DataArray, though.

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