arkouda icon indicating copy to clipboard operation
arkouda copied to clipboard

Add support for ascending list in `df.sort_values`

Open stress-tess opened this issue 1 year ago • 2 comments

Add support for something like this:

df.sort_values(by=['col_a', 'col_b'], ascending=[True, False])

Example of a workaround provided for user

>>> pd_df = pd.DataFrame({'col_a': (np.arange(5) % 2 == 0).astype(int), 'col_b': np.arange(5,0,-1), 'col_c': np.arange(5)})

>>> ak_df = ak.DataFrame(pd_df)

>>> def list_sort_values_workaround(df, col_names, order_list):
     return df[ak.coargsort([df[c_name] if ascend else -df[c_name] for c_name, ascend in zip(col_names, order_list)])]

stress-tess avatar Aug 16 '23 15:08 stress-tess

I think we basically just add an if isinstance(ascending, list) then do a size check. If those are both fine then return the line from the workaround

stress-tess avatar Aug 16 '23 15:08 stress-tess

it's also worth noting this only applies to numeric values. Right now we don't guarantee sorting on strings, categoricals anyway, only ordering

stress-tess avatar Aug 16 '23 15:08 stress-tess