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
537632653,MDExOlB1bGxSZXF1ZXN0NTM3NjMyNjUz,4683,closed,0,Readd order and subok parameters to astype (GH4644),32801740,"
- [x] Closes #4644
- [x] Tests added
- [x] Passes `isort . && black . && mypy . && flake8`
- [x] User visible changes (including notable bug fixes) are documented in `whats-new.rst`
",2020-12-12T01:27:35Z,2020-12-24T16:38:49Z,2020-12-16T16:33:00Z,2020-12-16T16:33:00Z,8039a954f0f04c683198687aaf43423609774a0c,,,0,af67e5489b58de2151aafa5fe7e8484d542a4061,19ebec52ef93ab8a640d04eb0edb7264823f6ba8,CONTRIBUTOR,,13221727,https://github.com/pydata/xarray/pull/4683,
547013664,MDExOlB1bGxSZXF1ZXN0NTQ3MDEzNjY0,4742,closed,0,speedup attribute style access and tab completion,32801740," - [x] Closes #4741
- [x] Passes `isort . && black . && mypy . && flake8`
- [x] User visible changes (including notable bug fixes) are documented in `whats-new.rst`
- make _attr_sources and _item_sources lazy
- make lookup of virtual dimension coordinates lazy
- make helper class more general so it can be used for lookup of both virtual dimension and level coordinates",2020-12-30T16:45:03Z,2021-01-05T23:00:34Z,2021-01-05T23:00:29Z,2021-01-05T23:00:29Z,7298df0c05168896a9813249b54a2d11f35cfa8f,,,0,aa92c310324383a2d93ce762c9b692fd7d7a2da9,8731accca9c718cc6b75f2a3749be0fe1db8172c,CONTRIBUTOR,,13221727,https://github.com/pydata/xarray/pull/4742,
550762631,MDExOlB1bGxSZXF1ZXN0NTUwNzYyNjMx,4774,closed,0,improve typing of OrderedSet,32801740,"- [x] Passes `isort . && black . && mypy . && flake8`
Small patch to improve typing of OrderedSet: allowing more general input type in its constructor and .update method (Iterator instead of AbstractSet) helps to get rid of ``# type: ignore``.
Side-effect: some performance gain in micro-benchmark (before and after):
```
%timeit xr.core.utils.OrderedSet(range(10))
3.46 µs ± 5.37 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
```
```
2.06 µs ± 6.39 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
```",2021-01-07T01:20:56Z,2021-01-07T23:28:53Z,2021-01-07T23:28:48Z,2021-01-07T23:28:48Z,1ae977867b59d5075df4b21f3ce61e3221e7cb87,,,0,0cc4e6ec58db285f28508c256be3cc380763ba29,bc49e277a45212f7ef33165d7fa1247c219ce276,CONTRIBUTOR,,13221727,https://github.com/pydata/xarray/pull/4774,
572948047,MDExOlB1bGxSZXF1ZXN0NTcyOTQ4MDQ3,4904,closed,0,add typing to unary and binary arithmetic operators,32801740,"- [x] Closes #4054
- [x] Passes `pre-commit run --all-files`
- [x] User visible changes (including notable bug fixes) are documented in `whats-new.rst`
This draft PR is for soliciting feedback on an approach to adding typing to unary and binary operators for xarray classes.
The approach involves generating a stub file using a simple script.
In order to untangle the various helper classes implementing arithmetic throughout the code base I have refactored the code, thereby getting rid of the injection of the operators after class definition. It now inserts the operators during construction of the subclasses leveraging Python's `__init_subclass__` mechanism.
For this example python file:
```
from typing import TYPE_CHECKING
from xarray import DataArray # noqa: F401
from xarray import Dataset # noqa: F401
from xarray import Variable # noqa: F401
ds = Dataset({""v"": (""x"", [2])})
da = DataArray([3], dims=""x"")
var = Variable(""x"", [4])
ds00 = -ds
ds01 = ds + ds
ds02 = da - ds
ds03 = ds * da
ds04 = var / ds
ds05 = ds // var
ds06 = ds & 1
ds07 = 2 | ds
ds08 = ds == ds
ds09 = ds != da
ds10 = da <= ds
ds11 = ds > var
ds12 = var >= ds
da0 = +da
da1 = da % da
da2 = da ** var
da3 = var ^ da
da4 = da & 123
da5 = 1.23 * da
da6 = da == da
da7 = da != var
da8 = var < da
var0 = ~var
var1 = var + var
var2 = var & 1
var3 = 3 ^ var
var4 = var != var
if TYPE_CHECKING:
reveal_locals() # noqa: F821
for k, v in tuple(vars().items()):
if k[0].islower():
print(k, type(v))
```
the status quo gives this mypy output:
```
temp.py:11: error: Unsupported operand type for unary - (""Dataset"")
temp.py:18: error: Unsupported operand types for | (""int"" and ""Dataset"")
temp.py:25: error: Unsupported operand type for unary + (""DataArray"")
temp.py:30: error: Unsupported operand types for * (""float"" and ""DataArray"")
temp.py:35: error: Unsupported operand type for ~ (""Variable"")
temp.py:38: error: Unsupported operand types for ^ (""int"" and ""Variable"")
temp.py:42: note: Revealed local types are:
temp.py:42: note: TYPE_CHECKING: builtins.bool
temp.py:42: note: da: xarray.core.dataarray.DataArray
temp.py:42: note: da0: Any
temp.py:42: note: da1: Any
temp.py:42: note: da2: Any
temp.py:42: note: da3: Any
temp.py:42: note: da4: Any
temp.py:42: note: da5: builtins.float
temp.py:42: note: da6: Any
temp.py:42: note: da7: Any
temp.py:42: note: da8: Any
temp.py:42: note: ds: xarray.core.dataset.Dataset
temp.py:42: note: ds00: Any
temp.py:42: note: ds01: Any
temp.py:42: note: ds02: Any
temp.py:42: note: ds03: Any
temp.py:42: note: ds04: Any
temp.py:42: note: ds05: Any
temp.py:42: note: ds06: Any
temp.py:42: note: ds07: builtins.int
temp.py:42: note: ds08: Any
temp.py:42: note: ds09: Any
temp.py:42: note: ds10: Any
temp.py:42: note: ds11: Any
temp.py:42: note: ds12: Any
temp.py:42: note: var: xarray.core.variable.Variable
temp.py:42: note: var0: Any
temp.py:42: note: var1: Any
temp.py:42: note: var2: Any
temp.py:42: note: var3: builtins.int
temp.py:42: note: var4: Any
Found 6 errors in 1 file (checked 127 source files)
```
With this PR the output now becomes:
```
temp.py:42: note: Revealed local types are:
temp.py:42: note: da: xarray.core.dataarray.DataArray
temp.py:42: note: da0: xarray.core.dataarray.DataArray*
temp.py:42: note: da1: xarray.core.dataarray.DataArray*
temp.py:42: note: da2: xarray.core.dataarray.DataArray*
temp.py:42: note: da3: xarray.core.dataarray.DataArray*
temp.py:42: note: da4: xarray.core.dataarray.DataArray*
temp.py:42: note: da5: xarray.core.dataarray.DataArray*
temp.py:42: note: da6: xarray.core.dataarray.DataArray*
temp.py:42: note: da7: xarray.core.dataarray.DataArray*
temp.py:42: note: da8: xarray.core.dataarray.DataArray*
temp.py:42: note: ds: xarray.core.dataset.Dataset
temp.py:42: note: ds00: xarray.core.dataset.Dataset*
temp.py:42: note: ds01: xarray.core.dataset.Dataset*
temp.py:42: note: ds02: xarray.core.dataset.Dataset*
temp.py:42: note: ds03: xarray.core.dataset.Dataset*
temp.py:42: note: ds04: xarray.core.dataset.Dataset*
temp.py:42: note: ds05: xarray.core.dataset.Dataset*
temp.py:42: note: ds06: xarray.core.dataset.Dataset*
temp.py:42: note: ds07: xarray.core.dataset.Dataset*
temp.py:42: note: ds08: xarray.core.dataset.Dataset*
temp.py:42: note: ds09: xarray.core.dataset.Dataset*
temp.py:42: note: ds10: xarray.core.dataset.Dataset*
temp.py:42: note: ds11: xarray.core.dataset.Dataset*
temp.py:42: note: ds12: xarray.core.dataset.Dataset*
temp.py:42: note: var: xarray.core.variable.Variable
temp.py:42: note: var0: xarray.core.variable.Variable*
temp.py:42: note: var1: xarray.core.variable.Variable*
temp.py:42: note: var2: xarray.core.variable.Variable*
temp.py:42: note: var3: xarray.core.variable.Variable*
temp.py:42: note: var4: xarray.core.variable.Variable*
```
",2021-02-13T15:01:59Z,2021-04-14T16:01:06Z,2021-04-14T15:59:59Z,2021-04-14T15:59:59Z,2896a80aaf1fb9ab5197e2c42c731369a2748c42,,,0,ff7ca3945f100e13325b9adeebba9b21e2c4313e,3cbd21aa8fd3a57c0dd324f2a276d83829518331,CONTRIBUTOR,,13221727,https://github.com/pydata/xarray/pull/4904,
985593049,PR_kwDOAMm_X846vvTZ,6746,closed,0,improve typing of DataArray and Dataset reductions,32801740,"This PR makes the typing of reduction methods (`count`, `all`, `any`, `max`, `min`, `mean`, `prod`, `sum`, `std`, `var`, `median`) for `Dataset` and `DataArray` consistent with the typing of most other methods of `Dataset` and `DataArray` after the great recent improvements by @headtr1ck in e.g. #6661.
",2022-07-02T21:06:41Z,2023-09-16T18:18:03Z,2023-09-14T12:13:58Z,2023-09-14T12:13:58Z,218ea21d79b5eaf04c982c235deb437a529bf35a,,,0,0277baad6a3816bdc6ecd4c61f935347ac72b118,8215911a8e1c97e58c3db071276a185b931b4a35,CONTRIBUTOR,"{""enabled_by"": {""login"": ""headtr1ck"", ""id"": 43316012, ""node_id"": ""MDQ6VXNlcjQzMzE2MDEy"", ""avatar_url"": ""https://avatars.githubusercontent.com/u/43316012?v=4"", ""gravatar_id"": """", ""url"": ""https://api.github.com/users/headtr1ck"", ""html_url"": ""https://github.com/headtr1ck"", ""followers_url"": ""https://api.github.com/users/headtr1ck/followers"", ""following_url"": ""https://api.github.com/users/headtr1ck/following{/other_user}"", ""gists_url"": ""https://api.github.com/users/headtr1ck/gists{/gist_id}"", ""starred_url"": ""https://api.github.com/users/headtr1ck/starred{/owner}{/repo}"", ""subscriptions_url"": ""https://api.github.com/users/headtr1ck/subscriptions"", ""organizations_url"": ""https://api.github.com/users/headtr1ck/orgs"", ""repos_url"": ""https://api.github.com/users/headtr1ck/repos"", ""events_url"": ""https://api.github.com/users/headtr1ck/events{/privacy}"", ""received_events_url"": ""https://api.github.com/users/headtr1ck/received_events"", ""type"": ""User"", ""site_admin"": false}, ""merge_method"": ""squash"", ""commit_title"": ""improve typing of DataArray and Dataset reductions (#6746)"", ""commit_message"": ""* improve typing of DataArray and Dataset reductions\r\n\r\n* fix some mypy errors\r\n\r\n* import Self from xarray.core.types\r\n\r\n\r\n---------\r\n\r\nCo-authored-by: Michael Niklas ""}",13221727,https://github.com/pydata/xarray/pull/6746,