[Python] What is the most efficient way to check if a Polars LazyFrame has duplicates?

Discussão em 'Python' iniciado por Stack, Agosto 4, 2025.

  1. Stack

    Stack Membro Participativo

    With the help of claude sonnet 4, I cooked up this function, which I hope does what I asked it to do.

    def has_duplicates_early_exit(df: pl.LazyFrame, subset: list[str]) -> bool:
    """Can exit early when first duplicate is found"""
    return df.select(
    pl.struct(subset).is_duplicated().any()
    ).collect().item()


    Is this the most efficient you can do?

    Continue reading...

Compartilhe esta Página