Skip to content

Fix #665 decode_cf_timedelta 2D #842

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

Merged
merged 3 commits into from
May 4, 2016
Merged

Conversation

ocefpaf
Copy link
Contributor

@ocefpaf ocefpaf commented May 3, 2016

Long time listener first time caller 😉

I am not 100% about this PR though. I think that there are cases when we need the actual data rather than the timedelta. In this notebook we have wave period ('mper') that should be seconds ranging 0-30 and not those big numpy timedelta numbers.

I know that I can get that behavior with decode_times=True when opening the dataset, but then the time coordinate get decoded as well. (Maybe I am way off and there is a way to do this.)

@@ -165,11 +165,18 @@ def decode_cf_timedelta(num_timedeltas, units):
"""
num_timedeltas = _asarray_or_scalar(num_timedeltas)
units = _netcdf_to_numpy_timeunit(units)

shape = None
if isinstance(num_timedeltas, np.ndarray):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would unilaterally convert to a numpy array: num_timedeltas = np.asarray(num_timedeltas). Then save the shape and ravel. Note that .ravel() is basically free for 1D data since it only makes a copy if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it. The only reason I did this way was to preserve the _asarray_or_scalar(x) behavior from above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure, but I think the _asarray_or_scalar is there because pandas's to_timedelta doesn't like receiving 0-dimensional numpy arrays as input. As long as you're flattening everything you pass to to_timedelta I think arrays should always be OK. Tests should tell us either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure, but I think the _asarray_or_scalar is there because pandas's to_timedelta doesn't like receiving 0-dimensional numpy arrays as input.

If that is the only reason it should go away. How does it look now?

@shoyer
Copy link
Member

shoyer commented May 4, 2016

Looks great! Please add a brief bug fix note to "What's new", then I will merge.

@ocefpaf
Copy link
Contributor Author

ocefpaf commented May 4, 2016

Looks great! Please add a brief bug fix note to "What's new", then I will merge.

How about 518ea53?

PS: @shoyer I am still not sure that converting any data that has units of time to timedelta is desirable as the default behavior. I may be biased but in my datasets (waves period data) we usually do not want that.

@@ -42,6 +42,9 @@ Bug fixes
``keep_attrs=True`` option. By
`Jeremy McGibbon <https://github.com/mcgibbon>`_.

- ``decode_cf_timedelta`` now accepts arrays with ``ndim`` >1 (pydata/xarray/pull/842).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to add your name in the credits!

also, reference the issue like this:

:issue:`842`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@shoyer
Copy link
Member

shoyer commented May 4, 2016

I agree that decoding time units to timedeltas is not always desirable -- possibly we should add an explicit toggle for decoding timedeltas vs datetimes.

@ocefpaf ocefpaf force-pushed the decode_cf_timedelta branch from 518ea53 to 888e6c2 Compare May 4, 2016 17:06
@ocefpaf
Copy link
Contributor Author

ocefpaf commented May 4, 2016

possibly we should add an explicit toggle for decoding timedeltas vs datetimes.

👍

I am opening a separated issue for that.

@shoyer
Copy link
Member

shoyer commented May 4, 2016

Thanks @ocefpaf !

@ocefpaf ocefpaf deleted the decode_cf_timedelta branch May 4, 2016 17:12
@ocefpaf
Copy link
Contributor Author

ocefpaf commented May 13, 2016

@shoyer I will be teaching a tutorial next Monday that will hit this bug. I know it is a lot to ask... But do you think you could cut a bugfix release? (I have a plan B be already, so no pressure.)

@shoyer
Copy link
Member

shoyer commented May 14, 2016

Sorry, I'm going camping this weekend so I won't be able to get this out.
Next time give me just a little bit more warning :).
On Fri, May 13, 2016 at 8:15 AM Filipe [email protected] wrote:

@shoyer https://github.com/shoyer I will be teaching a tutorial next
Monday that will hit this bug. I know it is a lot to ask... But do you
think you could cut a bugfix release? (I have a plan B
https://github.com/ioos/conda-recipes/pull/844/files be already, so no
pressure.)


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#842 (comment)

@ocefpaf
Copy link
Contributor Author

ocefpaf commented May 14, 2016

Sorry, I'm going camping this weekend so I won't be able to get this out.
Next time give me just a little bit more warning :).

No biggie. As I mentioned above I have a plan B (conda install of the latest dev version).

Enjoy your camping!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants