pull_requests: 1551300076
This data as json
id | node_id | number | state | locked | title | user | body | created_at | updated_at | closed_at | merged_at | merge_commit_sha | assignee | milestone | draft | head | base | author_association | auto_merge | repo | url | merged_by |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1551300076 | PR_kwDOAMm_X85cdvXs | 8294 | closed | 0 | Use shape and dtype as typevars in NamedArray | 14371165 | Using a different TypeVar strategy compared to #8281. The idea here is to typevar shape and dtype instead, just like numpy does. Previously I tried to use the _data array as the TypeVar but that causes all kinds of issues since TypeVar is usually invariant and can't be updated to a new type. Since the dtype changes very frequently when doing array operations it quickly gets difficult to pass along the correct typing. * This PR adds a from_array function. The intention is to use that function to create NamedArrays when you are passing around ArrayLikes. The init for NamedArray will now just assume the input data is correct. At runtime at least, mypy will catch any non-supported array types. There's some precedent to this: * numpy.array_api.Array forces to use xp.asarray. * [Cubed](https://github.com/tomwhite/cubed/blob/main/cubed/array_api/array_object.py) assumes the inputs are correct. Has a xp.asarray and a from_array function. * The ugly `fastpath` argument is therefore not needed. * Adds a bunch of type hint classes, `duckarray[ShapeType, DType]` (corresponding to `np.ndarray`) or `DuckArray[ScalarType]` (corresponding to `np.typing.NDArray`) are the recommended ones. * It's better to use these kinds of classes over creating `is_duck_array` functions with typeguards because `isinstance` also works on the `else` clause. * This PR adds some array_api functions, the idea here is that NamedArray could also be array_api compliant. - [x] Tests added - [x] Closes #8291 References: https://github.com/tomwhite/cubed/blob/ea885193dd37d27917a24878b51bb086aaef5fb1/cubed/core/ops.py#L34 https://stackoverflow.com/questions/74633074/how-to-type-hint-a-generic-numpy-array https://numpy.org/doc/stable/reference/arrays.scalars.html#scalars https://github.com/numpy/numpy/blob/040ed2dc9847265c581a342301dd87d2b518a3c2/numpy/__init__.pyi#L1423 https://github.com/numpy/numpy/blob/040ed2dc9847265c581a342301dd87d2b518a3c2/numpy/_typing/_array_like.py#L32 https://stackoverflow.com/questions/69186176/determine-if-subclass-has-a-base-classs-method-implemented-in-python | 2023-10-11T05:08:32Z | 2023-12-12T20:41:29Z | 2023-10-18T06:22:52Z | 2023-10-18T06:22:52Z | 087fe45266c7d2e0a651eca41a8d3ed8b4b5faa5 | 0 | 9bf347f61b28fcbdc1e0be7292cf71d22972d413 | c25c825f0655be4dec0f6d41eb570b84b47f7616 | MEMBER | { "enabled_by": { "login": "Illviljan", "id": 14371165, "node_id": "MDQ6VXNlcjE0MzcxMTY1", "avatar_url": "https://avatars.githubusercontent.com/u/14371165?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Illviljan", "html_url": "https://github.com/Illviljan", "followers_url": "https://api.github.com/users/Illviljan/followers", "following_url": "https://api.github.com/users/Illviljan/following{/other_user}", "gists_url": "https://api.github.com/users/Illviljan/gists{/gist_id}", "starred_url": "https://api.github.com/users/Illviljan/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Illviljan/subscriptions", "organizations_url": "https://api.github.com/users/Illviljan/orgs", "repos_url": "https://api.github.com/users/Illviljan/repos", "events_url": "https://api.github.com/users/Illviljan/events{/privacy}", "received_events_url": "https://api.github.com/users/Illviljan/received_events", "type": "User", "site_admin": false }, "merge_method": "squash", "commit_title": "Use shape and dtype as typevars in NamedArray (#8294)", "commit_message": "* Add from_array function\r\n\r\n* Update core.py\r\n\r\n* some fixes\r\n\r\n* Update test_namedarray.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* fixes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* fixes\r\n\r\n* fixes\r\n\r\n* fixes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update utils.py\r\n\r\n* more\r\n\r\n* Update core.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update test_namedarray.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update core.py\r\n\r\n* fixes\r\n\r\n* fkxes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* more\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update test_namedarray.py\r\n\r\n* Update test_namedarray.py\r\n\r\n* Update test_namedarray.py\r\n\r\n* Update test_namedarray.py\r\n\r\n* Update test_namedarray.py\r\n\r\n* Update test_namedarray.py\r\n\r\n* Update test_namedarray.py\r\n\r\n* move to NDArray instead\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* more\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Rename and align more with numpy typing\r\n\r\n* Add duck type testing\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* docstring\r\n\r\n* Update test_namedarray.py\r\n\r\n* fixes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* more\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update utils.py\r\n\r\n* fixes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* more\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* more\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update core.py\r\n\r\n* fixes\r\n\r\n* final\r\n\r\n* Follow numpy's example more with typing\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update utils.py\r\n\r\n* Update utils.py\r\n\r\n* Update utils.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Create _array_api.py\r\n\r\n* Create _typing.py\r\n\r\n* Update core.py\r\n\r\n* Update utils.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update _typing.py\r\n\r\n* Update core.py\r\n\r\n* Update utils.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Will this make pre-commit happy?\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update _array_api.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* fixes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* more\r\n\r\n* Update core.py\r\n\r\n* fixes\r\n\r\n* Update test_namedarray.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* fixes\r\n\r\n* Use Self becuase Variable subclasses\r\n\r\n* fixes\r\n\r\n* Update test_namedarray.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* fixes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update core.py\r\n\r\n* Update core.py\r\n\r\n* Update core.py\r\n\r\n* Update variable.py\r\n\r\n* Update variable.py\r\n\r\n* fix array api, add docstrings\r\n\r\n* Fix typing so that a different array gets correct typing\r\n\r\n* add _new with correct typing in variable\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update core.py\r\n\r\n* shape usually stays the same when copying\r\n\r\n* Update variable.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update test_namedarray.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update test_namedarray.py\r\n\r\n* same shape when astyping\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Delete test_namedarray_sketching.py\r\n\r\n* typos\r\n\r\n* remove any typing for now\r\n\r\n* fixes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* fixes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update indexing.py\r\n\r\n* add namespace to some explicitindexing stuff\r\n\r\n* Update variable.py\r\n\r\n* Update duck_array_ops.py\r\n\r\n* Update duck_array_ops.py\r\n\r\n* fixes\r\n\r\n* Update variable.py\r\n\r\n* Fixes\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update test_variable.py\r\n\r\n* Revert \"Update test_variable.py\"\r\n\r\nThis reverts commit 6572abec1a583c5f2f230c7311df91b02cce17d3.\r\n\r\n* Update _array_api.py\r\n\r\n* Update _array_api.py\r\n\r\n* Update _array_api.py\r\n\r\n* as_compatible_data lose the typing\r\n\r\n* Update indexing.py\r\n\r\n* Update core.py\r\n\r\n* Update core.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update variable.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update variable.py\r\n\r\n* Update variable.py\r\n\r\n* Update indexing.py\r\n\r\n* Update xarray/core/variable.py\r\n\r\n* cleanup\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update core.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update core.py\r\n\r\n* Update xarray/core/variable.py\r\n\r\nCo-authored-by: Michael Niklas <mick.niklas@gmail.com>\r\n\r\n* Apply suggestions from code review\r\n\r\nCo-authored-by: Michael Niklas <mick.niklas@gmail.com>\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update core.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update core.py\r\n\r\n* Update core.py\r\n\r\n* [pre-commit.ci] auto fixes from pre-commit.com hooks\r\n\r\nfor more information, see https://pre-commit.ci\r\n\r\n* Update core.py\r\n\r\n---------\r\n\r\nCo-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>\r\nCo-authored-by: Michael Niklas <mick.niklas@gmail.com>" } |
13221727 | https://github.com/pydata/xarray/pull/8294 |
Links from other tables
- 1 row from pull_requests_id in labels_pull_requests