Skip to content

csvsort: support mixed ascending and descending columns - #1364

Open
Rober1208 wants to merge 1 commit into
wireservice:masterfrom
Rober1208:csvsort-mixed-directions
Open

Rober1208 wants to merge 1 commit into
wireservice:masterfrom
Rober1208:csvsort-mixed-directions

Conversation

@Rober1208

Copy link
Copy Markdown

csvsort can currently sort every selected column in the same direction, but cannot sort one column ascending and another descending. This adds a ~ prefix for descending column identifiers, so csvsort -c 'state,~total' data.csv sorts by state ascending and total descending within each state. The prefix also works on ranges; --reverse flips every direction.

The comparison keeps the existing type inference, null ordering, case-insensitive sorting, and stable order for ties. On Windows, csvsort now keeps --columns values literal so a leading ~ is not expanded as a home directory path. An exact column name beginning with ~ still selects that column as before.

Refs #931.

Validation:

  • The new mixed-direction regression failed on the unchanged base (6d19c625) with ColumnIdentifierError, then passed after the change.
  • PYTHONUTF8=1 python -m pytest -q --disable-warnings: 360 passed, 31 subtests passed.
  • flake8 csvkit tests, isort csvkit tests --check-only, check-manifest, and git diff --check: passed.

This contribution was implemented and verified by Codex AI on behalf of Rober1208. It has not had an independent human code review.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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