{"database": "github", "table": "issues", "is_view": false, "human_description_en": "where \"closed_at\" is on date 2024-03-26, state_reason = \"completed\" and user = 35968931 sorted by updated_at descending", "rows": [[2117248281, "I_kwDOAMm_X85-MqUZ", 8704, "Currently no way to create a Coordinates object without indexes for 1D variables", 35968931, "closed", 0, null, null, 4, "2024-02-04T18:30:18Z", "2024-03-26T13:50:16Z", "2024-03-26T13:50:15Z", "MEMBER", null, null, null, "### What happened?\r\n\r\nThe workaround described in https://github.com/pydata/xarray/pull/8107#discussion_r1311214263 does not seem to work on `main`, meaning that I think there is currently no way to create an `xr.Coordinates` object without 1D variables being coerced to indexes. This means there is no way to create a `Dataset` object without 1D variables becoming `IndexVariables` being coerced to indexes.\r\n\r\n### What did you expect to happen?\r\n\r\nI expected to at least be able to use the workaround described in https://github.com/pydata/xarray/pull/8107#discussion_r1311214263, i.e.\r\n\r\n```python\r\nxr.Coordinates({'x': ('x', uarr)}, indexes={})\r\n```\r\nwhere `uarr` is an un-indexable array-like.\r\n\r\n### Minimal Complete Verifiable Example\r\n\r\n```Python\r\nclass UnindexableArrayAPI:\r\n    ...\r\n\r\n\r\nclass UnindexableArray:\r\n    \"\"\"\r\n    Presents like an N-dimensional array but doesn't support changes of any kind, \r\n    nor can it be coerced into a np.ndarray or pd.Index.\r\n    \"\"\"\r\n    \r\n    _shape: tuple[int, ...]\r\n    _dtype: np.dtype\r\n    \r\n    def __init__(self, shape: tuple[int, ...], dtype: np.dtype) -> None:\r\n        self._shape = shape\r\n        self._dtype = dtype\r\n        self.__array_namespace__ = UnindexableArrayAPI\r\n\r\n    @property\r\n    def dtype(self) -> np.dtype:\r\n        return self._dtype\r\n    \r\n    @property\r\n    def shape(self) -> tuple[int, ...]:\r\n        return self._shape\r\n    \r\n    @property\r\n    def ndim(self) -> int:\r\n        return len(self.shape)\r\n\r\n    @property\r\n    def size(self) -> int:\r\n        return np.prod(self.shape)\r\n\r\n    @property\r\n    def T(self) -> Self:\r\n        raise NotImplementedError()\r\n\r\n    def __repr__(self) -> str:\r\n        return f\"UnindexableArray(shape={self.shape}, dtype={self.dtype})\"\r\n\r\n    def _repr_inline_(self, max_width):\r\n        \"\"\"\r\n        Format to a single line with at most max_width characters. Used by xarray.\r\n        \"\"\"\r\n        return self.__repr__()\r\n\r\n    def __getitem__(self, key, /) -> Self:\r\n        \"\"\"\r\n        Only supports extremely limited indexing.\r\n        \r\n        I only added this method because xarray will apparently attempt to index into its lazy indexing classes even if the operation would be a no-op anyway.\r\n        \"\"\"\r\n        from xarray.core.indexing import BasicIndexer\r\n        \r\n        if isinstance(key, BasicIndexer) and key.tuple == ((slice(None),) * self.ndim):\r\n            # no-op\r\n            return self\r\n        else:\r\n            raise NotImplementedError()\r\n\r\n    def __array__(self) -> np.ndarray:\r\n        raise NotImplementedError(\"UnindexableArrays can't be converted into numpy arrays or pandas Index objects\")\r\n```\r\n\r\n```python\r\nuarr = UnindexableArray(shape=(3,), dtype=np.dtype('int32'))\r\n\r\nxr.Variable(data=uarr, dims=['x'])  # works fine\r\n\r\nxr.Coordinates({'x': ('x', uarr)}, indexes={})  # works in xarray v2023.08.0\r\n```\r\nbut in versions after that it triggers the NotImplementedError in `__array__`:\r\n```python\r\n---------------------------------------------------------------------------\r\nNotImplementedError                       Traceback (most recent call last)\r\nCell In[59], line 1\r\n----> 1 xr.Coordinates({'x': ('x', uarr)}, indexes={})\r\n\r\nFile ~/Documents/Work/Code/xarray/xarray/core/coordinates.py:301, in Coordinates.__init__(self, coords, indexes)\r\n    299 variables = {}\r\n    300 for name, data in coords.items():\r\n--> 301     var = as_variable(data, name=name)\r\n    302     if var.dims == (name,) and indexes is None:\r\n    303         index, index_vars = create_default_index_implicit(var, list(coords))\r\n\r\nFile ~/Documents/Work/Code/xarray/xarray/core/variable.py:159, in as_variable(obj, name)\r\n    152     raise TypeError(\r\n    153         f\"Variable {name!r}: unable to convert object into a variable without an \"\r\n    154         f\"explicit list of dimensions: {obj!r}\"\r\n    155     )\r\n    157 if name is not None and name in obj.dims and obj.ndim == 1:\r\n    158     # automatically convert the Variable into an Index\r\n--> 159     obj = obj.to_index_variable()\r\n    161 return obj\r\n\r\nFile ~/Documents/Work/Code/xarray/xarray/core/variable.py:572, in Variable.to_index_variable(self)\r\n    570 def to_index_variable(self) -> IndexVariable:\r\n    571     \"\"\"Return this variable as an xarray.IndexVariable\"\"\"\r\n--> 572     return IndexVariable(\r\n    573         self._dims, self._data, self._attrs, encoding=self._encoding, fastpath=True\r\n    574     )\r\n\r\nFile ~/Documents/Work/Code/xarray/xarray/core/variable.py:2642, in IndexVariable.__init__(self, dims, data, attrs, encoding, fastpath)\r\n   2640 # Unlike in Variable, always eagerly load values into memory\r\n   2641 if not isinstance(self._data, PandasIndexingAdapter):\r\n-> 2642     self._data = PandasIndexingAdapter(self._data)\r\n\r\nFile ~/Documents/Work/Code/xarray/xarray/core/indexing.py:1481, in PandasIndexingAdapter.__init__(self, array, dtype)\r\n   1478 def __init__(self, array: pd.Index, dtype: DTypeLike = None):\r\n   1479     from xarray.core.indexes import safe_cast_to_index\r\n-> 1481     self.array = safe_cast_to_index(array)\r\n   1483     if dtype is None:\r\n   1484         self._dtype = get_valid_numpy_dtype(array)\r\n\r\nFile ~/Documents/Work/Code/xarray/xarray/core/indexes.py:469, in safe_cast_to_index(array)\r\n    459             emit_user_level_warning(\r\n    460                 (\r\n    461                     \"`pandas.Index` does not support the `float16` dtype.\"\r\n   (...)\r\n    465                 category=DeprecationWarning,\r\n    466             )\r\n    467             kwargs[\"dtype\"] = \"float64\"\r\n--> 469     index = pd.Index(np.asarray(array), **kwargs)\r\n    471 return _maybe_cast_to_cftimeindex(index)\r\n\r\nCell In[55], line 63, in UnindexableArray.__array__(self)\r\n     62 def __array__(self) -> np.ndarray:\r\n---> 63     raise NotImplementedError(\"UnindexableArrays can't be converted into numpy arrays or pandas Index objects\")\r\n\r\nNotImplementedError: UnindexableArrays can't be converted into numpy arrays or pandas Index objects\r\n```\r\n\r\n\r\n### MVCE confirmation\r\n\r\n- [x] Minimal example \u2014 the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.\r\n- [x] Complete example \u2014 the example is self-contained, including all data and the text of any traceback.\r\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.\r\n- [x] New issue \u2014 a search of GitHub Issues suggests this is not a duplicate.\r\n- [x] Recent environment \u2014 the issue occurs with the latest version of xarray and its dependencies.\r\n\r\n### Relevant log output\r\n\r\n_No response_\r\n\r\n### Anything else we need to know?\r\n\r\nContext is #8699\r\n\r\n### Environment\r\n\r\nVersions described above\r\n", "{\"url\": \"https://api.github.com/repos/pydata/xarray/issues/8704/reactions\", \"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", null, "completed", 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 date(\"closed_at\") = :p0 and \"state_reason\" = :p1 and \"user\" = :p2 order by updated_at desc limit 101", "params": {"p0": "2024-03-26", "p1": "completed", "p2": "35968931"}}, "facet_results": {"state": {"name": "state", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?closed_at__date=2024-03-26&state_reason=completed&user=35968931", "results": [{"value": "closed", "label": "closed", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2024-03-26&state_reason=completed&user=35968931&state=closed", "selected": false}], "truncated": false}, "repo": {"name": "repo", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?closed_at__date=2024-03-26&state_reason=completed&user=35968931", "results": [{"value": 13221727, "label": "xarray", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2024-03-26&state_reason=completed&user=35968931&repo=13221727", "selected": false}], "truncated": false}, "type": {"name": "type", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?closed_at__date=2024-03-26&state_reason=completed&user=35968931", "results": [{"value": "issue", "label": "issue", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2024-03-26&state_reason=completed&user=35968931&type=issue", "selected": false}], "truncated": false}}, "suggested_facets": [{"name": "created_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2024-03-26&state_reason=completed&user=35968931&_facet_date=created_at"}, {"name": "updated_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2024-03-26&state_reason=completed&user=35968931&_facet_date=updated_at"}, {"name": "closed_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2024-03-26&state_reason=completed&user=35968931&_facet_date=closed_at"}], "next": null, "next_url": null, "private": false, "allow_execute_sql": true, "query_ms": 31.242401804775}