1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Why does a nearest join_asof() return exact matches despite allow_exact_matches=False?

Discussão em 'Python' iniciado por Stack, Novembro 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am looking for the nearest non exact match on the dates column:

    import polars as pl

    df = pl.from_repr("""
    ┌─────┬────────────┐
    │ uid ┆ dates │
    │ --- ┆ --- │
    │ i64 ┆ date │
    ╞═════╪════════════╡
    │ 1 ┆ 2025-11-21 │
    │ 2 ┆ 2025-11-22 │
    │ 3 ┆ 2025-11-23 │
    │ 4 ┆ 2025-11-24 │
    │ 5 ┆ 2025-11-25 │
    └─────┴────────────┘
    """)

    # Self join_asof on date
    self_join = df.join_asof(
    df,
    on="dates",
    strategy="nearest",
    allow_exact_matches=False,
    coalesce=False,
    )


    Which gives me a self_join with exact matches:

    ┌─────┬────────────┬───────────┬─────────────┐
    │ uid ┆ dates ┆ uid_right ┆ dates_right │
    │ --- ┆ --- ┆ --- ┆ --- │
    │ i64 ┆ date ┆ i64 ┆ date │
    ╞═════╪════════════╪═══════════╪═════════════╡
    │ 1 ┆ 2025-11-21 ┆ 1 ┆ 2025-11-21 │
    │ 2 ┆ 2025-11-22 ┆ 2 ┆ 2025-11-22 │
    │ 3 ┆ 2025-11-23 ┆ 3 ┆ 2025-11-23 │
    │ 4 ┆ 2025-11-24 ┆ 4 ┆ 2025-11-24 │
    │ 5 ┆ 2025-11-25 ┆ 5 ┆ 2025-11-25 │
    └─────┴────────────┴───────────┴─────────────┘


    Is this a bug? (polars version 1.35.2)

    Continue reading...

Compartilhe esta Página