Skip to content

Conversation

@alixdamman
Copy link
Collaborator

No description provided.

@alixdamman alixdamman requested a review from gdementen October 23, 2017 11:55
@alixdamman alixdamman added this to the 0.27 milestone Oct 23, 2017
* added a feature (see the :ref:`miscellaneous section <misc>` for details).

* added `reverse` argument to methods `indicesofsorted` and `labelsofsorted`.
When used values are sorted in descending order instead of ascending (default behavior):
Copy link
Contributor

Choose a reason for hiding this comment

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

s/.\nWhen used values are sorted/ to sort values/ ?

FR F M
IT M F
>>> arr.labelsofsorted(X.sex, reverse=True)
nat\\sex 1 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is the result we want. At least that was not what I needed when I wanted reverse: I expected:

         nat\\sex  0  1
              BE  F  M
              FR  M  F
              IT  F  M

The reasoning is this: I want to sort from highest to lowest, and given that sort, I want to know which is the first element (ie indice 0), which is second(1), etc. Not just display them in flipped order.

2 1 0
>>> arr.indicesofsorted(X.nat, reverse=True)
nat\\sex M F
2 1 0
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above

posargmax = renamed_to(indexofmax, 'posargmax')

def labelsofsorted(self, axis=None, kind='quicksort'):
def labelsofsorted(self, axis=None, kind='quicksort', reverse=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if reverse shouldn't be the second argument, as it is much more likely to be used than kind.

axis = self.axes[0]
axis, axis_idx = self.axes[axis], self.axes.index(axis)
data = self.data.argsort(axis_idx, kind=kind)
data = np.argsort(-1 * self.data if reverse else self.data, axis_idx, kind=kind)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use something like this:

data = self.data.argsort(axis_idx, kind=kind)
if reverse:
    reverser = tuple(slice(None, None, -1) if i == axis_idx else slice(None)
                     for i in range(self.ndim))
    data = data[reverser]

this wouldn't make a copy of the data.

if axis is None:
if self.ndim > 1:
raise ValueError("array has ndim > 1 and no axis specified for posargsort")
raise ValueError("array has ndim > 1 and no axis specified for indicesofsorted")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch! The corresponding message in labelsofsorted needs to be fixed too, though.

kind : {'quicksort', 'mergesort', 'heapsort'}, optional
Sorting algorithm. Defaults to 'quicksort'.
Copy link
Contributor

Choose a reason for hiding this comment

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

kill this extra space

@alixdamman
Copy link
Collaborator Author

Wainting for 0.26.1 release before to merge

Copy link
Contributor

@gdementen gdementen left a comment

Choose a reason for hiding this comment

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

squash & wait for 0.26.1 though.

@gdementen
Copy link
Contributor

can be merged now

@alixdamman alixdamman merged commit d3e7180 into larray-project:master Oct 25, 2017
@alixdamman alixdamman deleted the reverse_arg_490 branch October 25, 2017 20:18
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