{"database": "github", "table": "issues", "is_view": false, "human_description_en": "where comments = 4, repo = 13221727 and user = 20629530 sorted by updated_at descending", "rows": [[1235725650, "I_kwDOAMm_X85Jp61S", 6607, "Coordinate promotion workaround broken", 20629530, "closed", 0, 4160723, null, 4, "2022-05-13T21:20:25Z", "2022-09-27T09:33:41Z", "2022-09-27T09:33:41Z", "CONTRIBUTOR", null, null, null, "### What happened?\n\nOk so this one is a bit weird. I'm not sure this is a bug, but code that worked before doesn't anymore, so it is some sort of regression.\r\n\r\nI have a dataset with one dimension and one coordinate along that one, but they have different names. I want to transform this so that the coordinate name becomes the dimension name so it becomes are proper dimension-coordinate (I don't know how to call it).  After renaming the dim to the coord's name, it all looks good in the repr, but the coord still is missing an `index` for that dimension (`crd.indexes` is empty, see MCVE). There was a workaround through `reset_coords` for this, but it doesn't work anymore.\r\n\r\nInstead, the last line of the MCVE downgrades the variable, the final `lon` doesn't have coords anymore. \n\n### What did you expect to happen?\n\nIn the MCVE below, I show what the old \"workaround\" was. I expected `lon.indexes` to contain the indexes `lon` at the end of the procedure. \n\n### Minimal Complete Verifiable Example\n\n```Python\nimport xarray as xr\r\n\r\n# A dataset with a 1d variable along a dimension\r\nds = xr.Dataset({'lon': xr.DataArray([1, 2, 3], dims=('x',))})\r\n\r\n# Promote to coord. This still is not a proper crd-dim (different name)\r\nds = ds.set_coords(['lon'])\r\n\r\n# Rename dim:\r\nds = ds.rename(x='lon')\r\n\r\n# Now do we have a proper coord-dim ? No. not yet because:\r\nds.indexes # is empty\r\n\r\n# Workaround that was used up to the last release\r\nlon = ds.lon.reset_coords(drop=True)\r\n\r\n# Because of the missing indexes the next line fails on the master\r\nlon - lon.diff('lon')\n```\n\n\n### MVCE confirmation\n\n- [X] Minimal example \u2014 the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.\n- [X] Complete example \u2014 the example is self-contained, including all data and the text of any traceback.\n- [X] Verifiable example \u2014 the example copy & pastes into an IPython prompt or [Binder notebook](https://mybinder.org/v2/gh/pydata/xarray/main?urlpath=lab/tree/doc/examples/blank_template.ipynb), returning the result.\n- [x] New issue \u2014 a search of GitHub Issues suggests this is not a duplicate.\n\n### Relevant log output\n\n_No response_\n\n### Anything else we need to know?\n\nMy guess is that this line is causing `reset_coords` to drop the coordinate from itself : https://github.com/pydata/xarray/blob/c34ef8a60227720724e90aa11a6266c0026a812a/xarray/core/dataarray.py#L866\r\n\r\nIt would be nice if the renaming was sufficient for the indexes to appear. \r\n\r\nMy example is weird I know. The real use case is a script where we receive a 2d coordinate but where all lines are the same, so we take the first line and promote it to a proper coord-dim. But the current code fails on the master on the `lon - lon.diff('lon')` step that happens afterwards.\n\n### Environment\n\n<details>\r\n\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:22:55) \r\n[GCC 10.3.0]\r\npython-bits: 64\r\nOS: Linux\r\nOS-release: 5.13.19-2-MANJARO\r\nmachine: x86_64\r\nprocessor: \r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: fr_CA.UTF-8\r\nLOCALE: ('fr_CA', 'UTF-8')\r\nlibhdf5: None\r\nlibnetcdf: None\r\n\r\nxarray: 2022.3.1.dev104+gc34ef8a6\r\npandas: 1.4.2\r\nnumpy: 1.22.2\r\nscipy: 1.8.0\r\nnetCDF4: None\r\npydap: installed\r\nh5netcdf: None\r\nh5py: None\r\nNio: None\r\nzarr: None\r\ncftime: 1.5.2\r\nnc_time_axis: None\r\nPseudoNetCDF: None\r\nrasterio: None\r\ncfgrib: None\r\niris: None\r\nbottleneck: None\r\ndask: 2022.02.1\r\ndistributed: 2022.2.1\r\nmatplotlib: None\r\ncartopy: None\r\nseaborn: None\r\nnumbagg: None\r\nfsspec: 2022.3.0\r\ncupy: None\r\npint: None\r\nsparse: 0.13.0\r\nsetuptools: 59.8.0\r\npip: 22.0.3\r\nconda: None\r\npytest: 7.0.1\r\nIPython: 8.3.0\r\nsphinx: None\r\n\r\n\r\n\r\n</details>\r\n", "{\"url\": \"https://api.github.com/repos/pydata/xarray/issues/6607/reactions\", \"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", null, "completed", 13221727, "issue"], [798592803, "MDU6SXNzdWU3OTg1OTI4MDM=", 4853, "cftime default's datetime breaks CFTimeIndex", 20629530, "open", 0, null, null, 4, "2021-02-01T18:14:21Z", "2021-02-05T18:48:31Z", null, "CONTRIBUTOR", null, null, null, "<!-- Please include a self-contained copy-pastable example that generates the issue if possible.\r\n\r\nPlease be concise with code posted. See guidelines below on how to provide a good bug report:\r\n\r\n- Craft Minimal Bug Reports: http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports\r\n- Minimal Complete Verifiable Examples: https://stackoverflow.com/help/mcve\r\n\r\nBug reports that follow these guidelines are easier to diagnose, and so are often handled much more quickly.\r\n-->\r\n\r\n**What happened**:\r\nWith `cftime` 1.2.0, one can create datetime object with `cftime.datetime(*args, calendar='calendar')`, instead of using one of the subclasses (ex `cftime.DatetimeNoLeap(*args)`). In the latest release (1.4.0, yesterday), the subclasses have been deprecated, but kept as legacy. While all xr code still works (it is using the legacy subclasses), the `CFTimeIndex` object relies on the _type_ of the datetime object in order to infer the calendar. If the datetime was created outside xarray, using the now default constructor, the returned type is not understood and `CFTimeIndex`breaks.\r\n\r\n**What you expected to happen**:\r\nI expected `CFTimeIndex` to be independent of the way the datetime object is created.\r\n\r\n**Minimal Complete Verifiable Example**:\r\n\r\n```python3\r\nimport cftime\r\nimport numpy as np\r\nimport xarray as xr\r\n\r\n# A datetime array, not created in xarray\r\ntime = cftime.num2date(np.arange(365), \"days since 2000-01-01\", calendar=\"noleap\")\r\na = xr.DataArray(np.zeros(365), dims=('time',), coords={'time': time})\r\n\r\na.indexes['time']\r\n```\r\nFails with : \r\n```python3\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/home/phobos/Python/xclim/.tox/py38/lib/python3.8/site-packages/xarray/coding/cftimeindex.py\", line 342, in __repr__\r\n    attrs_str = format_attrs(self)\r\n  File \"/home/phobos/Python/xclim/.tox/py38/lib/python3.8/site-packages/xarray/coding/cftimeindex.py\", line 264, in format_attrs\r\n    attrs[\"freq\"] = f\"'{index.freq}'\" if len(index) >= 3 else None\r\n  File \"/home/phobos/Python/xclim/.tox/py38/lib/python3.8/site-packages/xarray/coding/cftimeindex.py\", line 692, in freq\r\n    return infer_freq(self)\r\n  File \"/home/phobos/Python/xclim/.tox/py38/lib/python3.8/site-packages/xarray/coding/frequencies.py\", line 96, in infer_freq\r\n    inferer = _CFTimeFrequencyInferer(index)\r\n  File \"/home/phobos/Python/xclim/.tox/py38/lib/python3.8/site-packages/xarray/coding/frequencies.py\", line 105, in __init__\r\n    self.values = index.asi8\r\n  File \"/home/phobos/Python/xclim/.tox/py38/lib/python3.8/site-packages/xarray/coding/cftimeindex.py\", line 673, in asi8\r\n    [\r\n  File \"/home/phobos/Python/xclim/.tox/py38/lib/python3.8/site-packages/xarray/coding/cftimeindex.py\", line 674, in <listcomp>\r\n    _total_microseconds(exact_cftime_datetime_difference(epoch, date))\r\n  File \"/home/phobos/Python/xclim/.tox/py38/lib/python3.8/site-packages/xarray/core/resample_cftime.py\", line 370, in exact_cftime_datetime_difference\r\n    seconds = b.replace(microsecond=0) - a.replace(microsecond=0)\r\n  File \"src/cftime/_cftime.pyx\", line 1153, in cftime._cftime.datetime.__sub__\r\nValueError: cannot compute the time difference between dates with different calendars\r\n```\r\n**Anything else we need to know?**:\r\n\r\n**Environment**:\r\n\r\n<details><summary>Output of <tt>xr.show_versions()</tt></summary>\r\n\r\n<!-- Paste the output here xr.show_versions() here -->\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 3.8.5 | packaged by conda-forge | (default, Jul 31 2020, 02:39:48) \r\n[GCC 7.5.0]\r\npython-bits: 64\r\nOS: Linux\r\nOS-release: 5.10.11-arch1-1\r\nmachine: x86_64\r\nprocessor: \r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: fr_CA.utf8\r\nLOCALE: fr_CA.UTF-8\r\nlibhdf5: 1.12.0\r\nlibnetcdf: 4.7.4\r\n\r\nxarray: 0.16.2\r\npandas: 1.2.1\r\nnumpy: 1.20.0\r\nscipy: 1.6.0\r\nnetCDF4: 1.5.5.1\r\npydap: None\r\nh5netcdf: None\r\nh5py: None\r\nNio: None\r\nzarr: None\r\ncftime: 1.4.0\r\nnc_time_axis: None\r\nPseudoNetCDF: None\r\nrasterio: None\r\ncfgrib: None\r\niris: None\r\nbottleneck: 1.3.2\r\ndask: 2021.01.1\r\ndistributed: None\r\nmatplotlib: None\r\ncartopy: None\r\nseaborn: None\r\nnumbagg: None\r\npint: 0.16.1\r\nsetuptools: 46.1.3\r\npip: 20.1\r\nconda: None\r\npytest: 6.2.2\r\nIPython: 7.19.0\r\nsphinx: None\r\n\r\n</details>\r\n", "{\"url\": \"https://api.github.com/repos/pydata/xarray/issues/4853/reactions\", \"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", null, null, 13221727, "issue"]], "truncated": false, "filtered_table_rows_count": 2, "expanded_columns": [], "expandable_columns": [[{"column": "repo", "other_table": "repos", "other_column": "id"}, "name"], [{"column": "milestone", "other_table": "milestones", "other_column": "id"}, "title"], [{"column": "assignee", "other_table": "users", "other_column": "id"}, "login"], [{"column": "user", "other_table": "users", "other_column": "id"}, "login"]], "columns": ["id", "node_id", "number", "title", "user", "state", "locked", "assignee", "milestone", "comments", "created_at", "updated_at", "closed_at", "author_association", "active_lock_reason", "draft", "pull_request", "body", "reactions", "performed_via_github_app", "state_reason", "repo", "type"], "primary_keys": ["id"], "units": {}, "query": {"sql": "select id, node_id, number, title, user, state, locked, assignee, milestone, comments, created_at, updated_at, closed_at, author_association, active_lock_reason, draft, pull_request, body, reactions, performed_via_github_app, state_reason, repo, type from issues where \"comments\" = :p0 and \"repo\" = :p1 and \"user\" = :p2 order by updated_at desc limit 101", "params": {"p0": "4", "p1": "13221727", "p2": "20629530"}}, "facet_results": {"state": {"name": "state", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?comments=4&repo=13221727&user=20629530", "results": [{"value": "closed", "label": "closed", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&repo=13221727&user=20629530&state=closed", "selected": false}, {"value": "open", "label": "open", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&repo=13221727&user=20629530&state=open", "selected": false}], "truncated": false}, "repo": {"name": "repo", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?comments=4&repo=13221727&user=20629530", "results": [{"value": 13221727, "label": "xarray", "count": 2, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&user=20629530", "selected": true}], "truncated": false}, "type": {"name": "type", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?comments=4&repo=13221727&user=20629530", "results": [{"value": "issue", "label": "issue", "count": 2, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&repo=13221727&user=20629530&type=issue", "selected": false}], "truncated": false}}, "suggested_facets": [{"name": "created_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&repo=13221727&user=20629530&_facet_date=created_at"}, {"name": "updated_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&repo=13221727&user=20629530&_facet_date=updated_at"}, {"name": "closed_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&repo=13221727&user=20629530&_facet_date=closed_at"}], "next": null, "next_url": null, "private": false, "allow_execute_sql": true, "query_ms": 176.7699532210827}