Skip to content

Sort API with asc and desc #1518

@kwmsmith

Description

@kwmsmith

This is an expanded description of the improvement to sort's API mentioned in #1307.

Currently, sort() separates the columns to sort in the key argument, and only supports sorting ascending or descending for all columns specified via the ascending boolean argument.

The improvement here is to allow the user to specify ascending and descending sort on a per-column basis.

The API will look something like:

expr.sort(bz.asc(expr.a), bz.desc(expr.b))

Equivalent variants:

expr.sort(bz.asc('a'), bz.desc('b')) # strings supported
expr.sort(bz.asc(expr.a), bz.desc('b')) # mixed mode supported
expr.sort('a', bz.desc('b')) # if not specified, defaults to ascending.
expr.sort(expr.a.asc(), expr.b.desc()) # method-call form.

Tasks:

  • implement new asc and desc expressions.
  • implement validation logic to ensure that asc and desc are only used in a sorting context.
  • re-implement sort() to accept asc and desc expression objects.
  • re-implement sort() on pandas
  • re-implement sort() on SQL.
  • tests...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions