home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 1477467808

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/7652#issuecomment-1477467808 https://api.github.com/repos/pydata/xarray/issues/7652 1477467808 IC_kwDOAMm_X85YEF6g 5821660 2023-03-21T08:55:37Z 2023-03-21T10:09:12Z MEMBER

A similar problem where saving, loading, saving, loading changes the dtype bool -> int8:

That's an issue with netcdf file format, too, it has no bool-dtype. XRef: https://github.com/pydata/xarray/issues/1500

python data = np.array([True], dtype=bool) with nc.Dataset("test-bool-netcdf4.nc", mode="w") as ds: ds.createDimension("x", size=1) var = ds.createVariable("da", data.dtype.str, dimensions=("x")) var[:] = data ```


TypeError Traceback (most recent call last) Cell In[42], line 4 2 with nc.Dataset("test-bool-netcdf4.nc", mode="w") as ds: 3 ds.createDimension("x", size=1) ----> 4 var = ds.createVariable("da", data.dtype.str, dimensions=("x")) 5 var[:] = data

File src/netCDF4/_netCDF4.pyx:2945, in netCDF4._netCDF4.Dataset.createVariable()

File src/netCDF4/_netCDF4.pyx:4121, in netCDF4._netCDF4.Variable.init()

TypeError: illegal primitive data type, must be one of dict_keys(['S1', 'i1', 'u1', 'i2', 'u2', 'i4', 'u4', 'i8', 'u8', 'f4', 'f8']), got bool ```

Update: Xarray is forwarding the information to the file, by adding a dtype-attribute. It looks like this information is not correctly distributed back to .encoding in the case of saving/loading/saving/loading. I'd consider that one a bug.

Reason: While decoding the .encoding-dtype is set as original_dtype (int8 in our case), but it should either be removed or explicitely set as bool.

https://github.com/pydata/xarray/blob/f1ff956ff67f3c053a2514d93d35929059e17b07/xarray/conventions.py#L400-L404

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  1632718954
Powered by Datasette · Queries took 0.535ms · About: xarray-datasette