{"database": "github", "table": "issues", "is_view": false, "human_description_en": "where comments = 4, state = \"open\" and user = 20629530 sorted by updated_at descending", "rows": [[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": 1, "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 \"state\" = :p1 and \"user\" = :p2 order by updated_at desc limit 101", "params": {"p0": "4", "p1": "open", "p2": "20629530"}}, "facet_results": {"state": {"name": "state", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?comments=4&state=open&user=20629530", "results": [{"value": "open", "label": "open", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&user=20629530", "selected": true}], "truncated": false}, "repo": {"name": "repo", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?comments=4&state=open&user=20629530", "results": [{"value": 13221727, "label": "xarray", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&state=open&user=20629530&repo=13221727", "selected": false}], "truncated": false}, "type": {"name": "type", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?comments=4&state=open&user=20629530", "results": [{"value": "issue", "label": "issue", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&state=open&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&state=open&user=20629530&_facet_date=created_at"}, {"name": "updated_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?comments=4&state=open&user=20629530&_facet_date=updated_at"}], "next": null, "next_url": null, "private": false, "allow_execute_sql": true, "query_ms": 26.23767778277397}