Skip to content

Conversation

smartass101
Copy link

  • {Dataset,DataArray}.diff dim argument defaults to last dimension

  • add test cases

  • add changelog

* {Dataset,DataArray}.diff dim argument defaults to last dimension

* add test cases

* add changelog
@@ -2156,6 +2157,10 @@ def diff(self, dim, n=1, label='upper'):
raise ValueError('order `n` must be non-negative but got {0}'
''.format(n))

# get default last dim if not specified
if dim is None:
dim = self.dims[-1]
Copy link
Member

Choose a reason for hiding this comment

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

This isn't going to work -- self.dims is an sorted dict on Dataset. Moreover, Dataset dims are actually always in sorted order, so the default isn't very sensible.

We could make the default dim be determined per variable, but that wouldn't work very well if different variables had different dimensions or dimension orders.

I think the simplest thing to do is to only allow omitting dim if the dataset has only one dimension.

Copy link
Author

Choose a reason for hiding this comment

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

Doing this only for 1D is possible, but would make the docstring somewhat less obvious.

Something like dim, optional for 1D ?

Copy link
Member

Choose a reason for hiding this comment

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

Sure.

@jhamman
Copy link
Member

jhamman commented Jul 13, 2017

In reviewing this PR, I'm not really a fan of special casing the 1-D array in the way described above. These sorts of decisions lead to unexpected/confusing behavior when scaling up analysis. Obviously there is a tradeoff here as we diverge from how the numpy.diff function works but I think that is something we'd prefer to live with. I think this falls under the explicit is better than implicit idea...

@max-sixty
Copy link
Collaborator

Closing as stale. Please feel free to reopen!

@max-sixty max-sixty closed this Jan 14, 2019
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.

4 participants