home / github / issues

Menu
  • GraphQL API
  • Search all tables

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).

  1. Direct assignment (dupe of #4612)

```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

```

  1. Via a numpy function (pad, shift, rolling)

pad

```python da.pad(x=1, constant_values=np.nan)

ValueError: cannot convert float NaN to integer

da.pad(x=1, constant_values=None)

casts da to float

da.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:

  • What does dask do in these cases?
  • What does pandas do?
  • What about str dtypes?
{
    "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

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 0 rows from issue in issue_comments
Powered by Datasette · Queries took 0.676ms · About: xarray-datasette