asq icon indicating copy to clipboard operation
asq copied to clipboard

order_by(self, func=identity, descending=False)

Open s-celles opened this issue 5 years ago • 3 comments

Hello,

I noticed

https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L609

and

https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/parallel_queryable.py#L166

I wonder if having descending keyword couldn't be a nice API improvement.

when descending is True, order_by_descending will be called.

What is your opinion?

Kind regards

s-celles avatar Nov 23 '20 09:11 s-celles

What about an enum? order_by(order=ascending) or order_by(order=descending)

rob-smallshire avatar Nov 23 '20 10:11 rob-smallshire

enum or boolean. It is as you want. My idea was using boolean, as in reverse parameter of sorted function

sorted(iterable, /, *, key=None, reverse=False)

or in Pandas DataFrame.sort_values method with ascending parameter

DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None)[source]

s-celles avatar Nov 23 '20 12:11 s-celles

A boolean is simpler because it avoid having to import these enum values. but I noticed in your code that you are using order (-1 or 1) which is an other possibility

s-celles avatar Nov 24 '20 05:11 s-celles