issues: 802992417
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
802992417 | MDU6SXNzdWU4MDI5OTI0MTc= | 4875 | assigning values with incompatible dtype | 10194086 | open | 0 | 0 | 2021-02-07T16:28:24Z | 2021-02-07T16:28:24Z | MEMBER | The behavior of xarray when assigning values with incompatible dtypes is a bit arbitrary. This is partly due to the behavior of numpy.... numpy 1.20 got a bit cleverer but still seems inconsistent at times... I am not sure what to do about this (and if we should actually be clever here).
```python import xarray as xr import numpy as np arr = np.array([2]) arr[0] = np.nan ValueError (since numpy 1.20)arr[0:1] = np.array([np.nan]) -> array([-9223372036854775808])da = xr.DataArray([5], dims="x") da[0] = np.nan <xarray.DataArray (x: 1)>array([-9223372036854775808])Dimensions without coordinates: x(because this gets converted to da.variable._data[0:1, 0:1] = np.array([np.nan]) (approximately). da[0] = 1.2345 casts constant_values to int```
pad ```python da.pad(x=1, constant_values=np.nan) ValueError: cannot convert float NaN to integerda.pad(x=1, constant_values=None) casts da to floatda.pad(x=1, constant_values=1.5) casts constant_values to int```
**shift**
```python
da.shift(x=1, fill_value=np.nan)
# ValueError: cannot convert float NaN to integer
# da.shift(x=1, fill_value=None)
# None not allowed by shift
da.shift(x=1, fill_value=1.5)
# casts fill_value to int
```
**rolling**
```python
da.rolling(x=1).construct("new_axis", stride=3, fill_value=np.nan)
# ValueError: cannot convert float NaN to integer
# da.rolling(x=1).construct("new_axis", stride=3, fill_value=None)
# None not allowed by rolling
da.rolling(x=3).construct("new_axis", stride=3, fill_value=1.5)
# casts fill_value to int
```
To check:
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/4875/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |