alifestd_downsample_tips_canopy_polars

alifestd_downsample_tips_canopy_polars(phylogeny_df: DataFrame, n_downsample: int | None = None, criterion: str | Expr = 'origin_time') DataFrame

Retain the n_downsample leaves with the largest criterion values and prune extinct lineages.

If n_downsample is None, it defaults to the number of leaves that share the maximum value of the criterion column. If n_downsample is greater than or equal to the number of leaves in the phylogeny, the whole phylogeny is returned. Ties are broken arbitrarily.

Only supports asexual phylogenies.

Parameters

phylogeny_dfpolars.DataFrame

The phylogeny as a dataframe in alife standard format.

Must represent an asexual phylogeny.

n_downsampleint, optional

Number of tips to retain. If None, defaults to the count of leaves with the maximum criterion value.

criterionstr or polars.Expr, default “origin_time”

Column name or polars expression used to rank leaves. The n_downsample leaves with the largest values are retained. Ties are broken arbitrarily.

Raises

NotImplementedError

If phylogeny_df has no “ancestor_id” column.

ValueError

If criterion is not a column in phylogeny_df.

Returns

polars.DataFrame

The pruned phylogeny in alife standard format.

See Also

alifestd_downsample_tips_canopy_asexual :

Pandas-based implementation.