New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timedelta64[D] is always coerced to timedelta64[ns] #1143
Comments
The conversion to timedelta64[ns] is done on this line of code: xarray/xarray/core/variable.py Line 169 in d66f673
Is there a reason behind the conversion, or could it be removed? |
Interesting. Pandas always uses nanosecond precision for
This might actually be a pandas bug -- as far as I recall, this goes against the documented behavior. |
The pandas docs do seem to say that conversion to timedelta64[D] (or other frequencies) is possible - see: http://pandas.pydata.org/pandas-docs/stable/timedeltas.html#frequency-conversion Also here's a more realistic example of why this is problematic for me - I have a sequence of dates and I want to calculate the difference between them in days: possible in pandas, but not possible in xarray without first reverting to pandas/numpy types
Again the xarray result is in ns rather than days. Thanks |
Pardon me for extending this discussion. I encountered the same problem when calculating timedelta in a dataframe. It even ended with an error when I tried to call the days attribute. I am using Numpy 1.6.1 AttributeError: 'Series' object has no attribute 'days' Problem df_trans['DELTA'] = df_trans['DATE2'] - df_trans['DATE1'] print df_trans['DELTA'].dtype
print df_trans['DELTA']
df_trans['DELTA'] = df_trans['DELTA'].astype('timedelta64[D]')
print df_trans['DELTA']
print df_trans['DELTA'].days
I get rid of the problem by putting it in to a list for the conversion.
|
|
Hi guys, the following snippets show the issue...
Compare this with Pandas:
This behvaiour becomes more problematic when trying to convert from timedelta[ns] to e.g. days as ints:
Again contrast that with pandas:
Other variations of timedelta e.g. timedelta64[s], timedelta64[W] etc suffer from the same problem.
Thanks
The text was updated successfully, but these errors were encountered: