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 751732952,MDU6SXNzdWU3NTE3MzI5NTI=,4612,Assigning nan to int-dtype array converts nan to int,500246,open,0,,,1,2020-11-26T17:00:45Z,2021-01-02T03:55:30Z,,CONTRIBUTOR,,,,"(I am almost sure this already exists as an issue, but I can't find the original) **What happened**: When assigning nan to a integer-dtype array, the nan gets incorrectly inverted to int. **What you expected to happen**: I expect to get a `ValueError`, like I get for pure numpy arrays. **Minimal Complete Verifiable Example**: ```python import xarray import numpy da = xarray.DataArray(numpy.array([0,1], dtype=""u8"")) da[0] = numpy.nan print(da) ``` Gives: ``` array([9223372036854775808, 1], dtype=uint64) Dimensions without coordinates: dim_0 ``` **Anything else we need to know?**: In numpy the equivalent code raises `ValueError` This is related but different from #2945. In #2945, xarray behaves the same as numpy. In #4612, xarray behaves differently from numpy. **Environment**:
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.8.6 | packaged by conda-forge | (default, Oct 7 2020, 19:08:05) [GCC 7.5.0] python-bits: 64 OS: Linux OS-release: 4.12.14-lp150.12.82-default machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 libhdf5: 1.10.6 libnetcdf: 4.7.4 xarray: 0.16.1 pandas: 1.1.4 numpy: 1.19.4 scipy: 1.5.3 netCDF4: 1.5.4 pydap: None h5netcdf: 0.8.1 h5py: 3.1.0 Nio: None zarr: 2.5.0 cftime: 1.2.1 nc_time_axis: None PseudoNetCDF: None rasterio: 1.1.7 cfgrib: None iris: None bottleneck: None dask: 2.30.0 distributed: 2.30.1 matplotlib: 3.3.2 cartopy: 0.18.0 seaborn: None numbagg: None pint: None setuptools: 49.6.0.post20201009 pip: 20.2.4 conda: installed pytest: 6.1.2 IPython: 7.19.0 sphinx: 3.3.0
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/4612/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,issue 410317757,MDU6SXNzdWU0MTAzMTc3NTc=,2772,Should xarray allow assigning a masked constant?,500246,open,0,,,1,2019-02-14T14:10:20Z,2019-02-15T20:24:44Z,,CONTRIBUTOR,,,,"Currently, `ds['a'] = ((), ma.masked)` where `ds` is an `xarray.Dataset` gives `ValueError: Could not convert tuple of form (dims, data[, attrs, encoding]): ((), masked) to Variable.`, whereas `ds['a'] = (), ma.MaskedArray(0.0, True)` works (it sets the indicated value to NaN). Should assigning `ma.masked` be equivalent to assigning `ma.MaskedArray(0.0, True)`, or are there good reasons for the difference in behaviour?","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2772/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,issue