home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 926877228

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-926877228 https://api.github.com/repos/pydata/xarray/issues/5815 926877228 IC_kwDOAMm_X843PwYs 4160723 2021-09-24T19:41:46Z 2021-09-24T19:41:46Z MEMBER

Beware when you set index attributes in place like xa_copy.get_index('time').freq = freq. Currently, Xarray internals are such that depending on how you access the index it may return distinct (although intially identical) objects, e.g.,

```python

xa_copy.get_index('time').freq = freq xa_copy._indexes['time'].index # freq set here 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') xa_copy._coords['time']._data.array # freq not set here 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=None) xa_copy._coords['time']._data.array is xa_copy._indexes['time'].index False ```

Hopefully, this will become less likely after the ongoing explicit index refactor in Xarray. But in general I would not advise changing in-place pandas indexes that are already bound to xarray objects. In your example it is safer to set freq when creating time_index.

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