home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 361089977

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/pull/1863#issuecomment-361089977 https://api.github.com/repos/pydata/xarray/issues/1863 361089977 MDEyOklzc3VlQ29tbWVudDM2MTA4OTk3Nw== 3404817 2018-01-28T19:45:49Z 2018-01-28T19:48:09Z CONTRIBUTOR

I believe the issue originates in these lines:

https://github.com/pydata/xarray/blob/ac854f081d4b57d292755d3aff1476f8e2e2da11/xarray/conventions.py#L174-L175

where we multiply the num_dates with some float value and then cast to int64.

If num_dates is float32, numpy keeps float32 when multiplying with e.g. 1e9 and that somehow introduces an error. Here is a stripped version of the above:

python flat_num_dates = np.arange(100).astype('float32') n = 1e9 roundtripped = (flat_num_dates * n).astype(np.int64) / n assert np.all(flat_num_dates == roundtripped)

By the way, the factor has to be large, like 1e9. E.g. 1e6 ('ms since ...') won't give the error.

The weird thing is that the corresponding code in the current master is identical:

https://github.com/pydata/xarray/blob/50b0a69a7aa0fb7ac3afb28e7bd971cf08055f99/xarray/coding/times.py#L151-L152

I will look into why the result is still different from v0.10.0.

Also, if this really is the origin of the error, there are two easy ways to avoid this:

  1. Cast flat_num_dates to float64: (flat_num_dates.astype(np.float64) * n).astype(np.int64)
  2. Store _NS_PER_TIME_DELTA values as int, then numpy will do the casting.
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  292231408
Powered by Datasette · Queries took 0.854ms · About: xarray-datasette