issues: 1944083743
This data as json
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1944083743 | PR_kwDOAMm_X85c1vGB | 8315 | Handle numpy missing the array api function astype | 14371165 | closed | 0 | 1 | 2023-10-15T22:32:17Z | 2023-10-16T06:25:20Z | 2023-10-16T06:25:19Z | MEMBER | 0 | pydata/xarray/pulls/8315 | This is how our get_array_namespace works: https://github.com/pydata/xarray/blob/dafd726c36e24ac77427513a4a149a6933353b66/xarray/core/duck_array_ops.py#L44-L48 Which usually works. But not for astype. Using np.array_api doesn't work because you have to use np.array_api.Array instead of np.ndarray: ```python import numpy.array_api as nxp nxp.astype(np.array([1, 2,]), np.dtype(float)) Traceback (most recent call last): File "C:\Users\J.W\AppData\Local\Temp\ipykernel_8616\23329947.py", line 1, in <cell line: 1> nxp.astype(np.array([1, 2,]), np.dtype(float)) File "C:\Users\J.W\anaconda3\envs\xarray-tests\lib\site-packages\numpy\array_api_data_type_functions.py", line 20, in astype return Array._new(x._array.astype(dtype=dtype, copy=copy)) AttributeError: 'numpy.ndarray' object has no attribute '_array' ``` I found it simpler to just change astype here. An alternative solution would be to use: https://github.com/data-apis/array-api-compat https://github.com/tomwhite/cubed/pull/317 Seen in #8294. |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/8315/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | pull |