issues: 192325490
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
192325490 | MDU6SXNzdWUxOTIzMjU0OTA= | 1143 | timedelta64[D] is always coerced to timedelta64[ns] | 5629061 | closed | 0 | 5 | 2016-11-29T16:11:53Z | 2019-01-22T19:21:18Z | 2019-01-22T19:21:18Z | NONE | Hi guys, the following snippets show the issue... ``` xarray.DataArray([1,2,3,4]).astype('timedelta64[D]') output is""" <xarray.DataArray (dim_0: 4)> array([ 86400000000000, 172800000000000, 259200000000000, 345600000000000], dtype='timedelta64[ns]') Coordinates: * dim_0 (dim_0) int64 0 1 2 3 """ ``` Compare this with Pandas: ``` pandas.Series([1,2,3,4]).astype('timedelta64[D]') output is""" 0 1 days 1 2 days 2 3 days 3 4 days dtype: timedelta64[D] """ ``` This behvaiour becomes more problematic when trying to convert from timedelta[ns] to e.g. days as ints: ``` xarray.DataArray(pandas.Series([1,2,3,4]).astype('timedelta64[D]')).astype(int) output is""" <xarray.DataArray (dim_0: 4)> array([ 86400000000000, 172800000000000, 259200000000000, 345600000000000]) Coordinates: * dim_0 (dim_0) int64 0 1 2 3 """ ``` Again contrast that with pandas: ``` pandas.Series([1,2,3,4]).astype('timedelta64[D]').astype(int) output is""" 0 1 1 2 2 3 3 4 dtype: int64 """ ``` Other variations of timedelta e.g. timedelta64[s], timedelta64[W] etc suffer from the same problem. Thanks |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/1143/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |