alifestd_sort_children_polars

alifestd_sort_children_polars(phylogeny_df: DataFrame, criterion: str | Expr, reverse: bool = False) DataFrame

Reorder rows so children are sorted by the given criterion column, gathering children into contiguous rows.

Reorders rows so that among siblings, they appear in order of ascending criterion column values. Set reverse=True to sort descending (higher values first).

The criterion column must already be present in the dataframe.

Note: after sorting, ids will no longer be contiguous with respect to row indices. Call alifestd_assign_contiguous_ids_polars on the result to reassign contiguous ids if needed.

Parameters

phylogeny_dfpolars.DataFrame

The phylogeny as a dataframe in alife standard format.

Must represent an asexual phylogeny with contiguous ids and topologically sorted rows.

criterionstr or polars.Expr

Name of the column to sort children by, or a polars expression whose values determine the sort order.

reversebool, default False

If True, sort descending (higher values first).

Returns

polars.DataFrame

The phylogeny with rows reordered by sorted children traversal.

Raises

NotImplementedError

If ids are not contiguous or rows are not topologically sorted.

See Also

alifestd_sort_children_asexual :

Pandas-based implementation.

alifestd_ladderize_polars :

Convenience wrapper that sorts by num_leaves.

alifestd_assign_contiguous_ids_polars :

Reassign contiguous ids after reordering.