Nodes/ComfyUI-huggingface_dataset/πŸ€— Dataset Sort
ComfyUI Node

πŸ€— Dataset Sort

Sort by column, then flip with reverse β€” data wrangling's most underrated node

By StableLlamaΒ·Created a day agoΒ·Updated a day agoΒ· 1
πŸ€— Dataset Sort
  • dataset
  • dataset
β—„columnβ–Ί
β—„reversefalseβ–Ί

Sorting sounds like the least exciting node in the pack, right up until you need "the 10 longest prompts" or "the reviews with the highest scores first." Then it's the whole workflow. πŸ€— Dataset Sort reorders a loaded dataset's rows by a column, in either direction - and because it's a graph node, you can swap the column or flip the direction without editing code or reloading a thing.

How it works

It wraps datasets.Dataset.sort. Feed it a HUGGINGFACE_DATASET (from the loader or a prior πŸ€— node), name the column, and you get a new dataset back ordered by that column. Three inputs:

  • dataset - what to sort.
  • column - what to sort by. Numeric and string columns both work; datasets handles the type comparison for you.
  • reverse - a boolean that decides ascending (off, the default) or descending (on). The descending path is where most real use lives: top-scored first, longest first, newest first.

Output is a sorted HUGGINGFACE_DATASET you can chain into Take ("top 10"), To Data List, or anything else downstream.

The one thing that will trip you

This node is loaded-only, and it's the cleanest example of why the pack draws that line: you can't sort a lazily-iterated streaming dataset without pulling the whole thing into memory anyway, so the node refuses and tells you to disable streaming on the loader instead of pretending. If you see that error, that's the fix - flip streaming off and the sort gets its full materialized view.

Secondary gotcha: sorting is stable-ish in effect but not in intent - rows that compare equal under your column keep whatever relative order the source had, so if you need a secondary sort (e.g. by score, then by date), sort twice in the right order: sort by date first, then by score. And remember you're sorting the whole loaded dataset; for a huge one, a Take after the sort is your friend, not before - take(10) then sort would only sort the ten rows you kept.

Installing it

Part of the StableLlama/ComfyUI-huggingface_dataset pack. ComfyUI-Manager β†’ search "Hugging Face dataset", or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-huggingface_dataset
pip install -r requirements.txt

Restart ComfyUI. The only dependency is the datasets Python package, installed automatically by Manager.

CategoryHugging Face πŸ€—

Inputs (3)

NameTypeDefaultDescription
datasetHUGGINGFACE_DATASETFully-loaded dataset to sort (from the πŸ€— Dataset Loader or another dataset node).
columnSTRINGColumn to sort the rows by.
reverseBOOLEANfalseSort in descending order when enabled.

Outputs (1)

NameTypeDescription
datasetHUGGINGFACE_DATASETThe sorted dataset.