home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 874695249

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
874695249 MDU6SXNzdWU4NzQ2OTUyNDk= 5254 Boolean confusion 22542812 open 0     3 2021-05-03T15:53:54Z 2021-05-05T06:50:21Z   NONE      

True and True are treated different depending on whether it is a bool or a np.bool_. This creates absolute hellish errors. You save date, and load it again. Then bool turned to np.bool_ and things work differently. I.e. you cannot save your data again.

The following example works perfectly fine: ```python

data = xr.Dataset() data.attrs['bool_type'] = True data.to_netcdf() data <xarray.Dataset> Dimensions: () Data variables: empty Attributes: bool_type: True The following example however fails:python data = xr.Dataset() data.attrs['bool_type'] = np.True_ data.to_netcdf() TypeError: Invalid value for attr: True must be a number, a string, an ndarray or a list/tuple of numbers/strings for serialization to netCDF files data <xarray.Dataset> Dimensions: () Data variables: empty Attributes: bool_type: True ```

If you load the data again, in both cases np.True_ leading to confusing things, when the seemingly same things fails.

For this routine a simple remedy is probably expanding the instance check in check_attr:

python isinstance(value, (str, Number, np.ndarray, np.number, np.bool_, list, tuple))

As numpy warns, np.bool_ are no numbers in contrast to regular Python, see https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bool_.

I fear, however, that this problem runs deeper and the same issue might arise at different points.


edit: included TypeError

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5254/reactions",
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 3 rows from issue in issue_comments
Powered by Datasette · Queries took 0.696ms · About: xarray-datasette