Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow_exact_matches parameter in polars.DataFrame.join_asof #7932

Closed
wangkev opened this issue Apr 1, 2023 · 1 comment · Fixed by #20723
Closed

allow_exact_matches parameter in polars.DataFrame.join_asof #7932

wangkev opened this issue Apr 1, 2023 · 1 comment · Fixed by #20723
Labels
enhancement New feature or an improvement of an existing feature

Comments

@wangkev
Copy link

wangkev commented Apr 1, 2023

Problem description

pandas.merge_asof has an allow_exact_matches parameter. Can we add a similar parameter to polars.DataFrame.join_asof?

@wangkev wangkev added the enhancement New feature or an improvement of an existing feature label Apr 1, 2023
@cmdlineluser
Copy link
Contributor

This did come up on stackoverflow a while ago.

https://stackoverflow.com/questions/75068390/is-it-possible-to-disallow-exact-matches-on-join-asof

The suggestion was an anti-join beforehand to get:

shape: (3, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 2   ┆ 1   │
│ 4   ┆ 3   │
│ 6   ┆ 5   │
└─────┴─────┘

allow_exact_matches=False is slightly different though, it doesn't discard the exact match, it just considers it a non-match and continues searching.

pl.from_pandas(
   pd.merge_asof(
      df1.to_pandas(), 
      df2.to_pandas(), 
      direction="backward",
      allow_exact_matches=False
   )
)
shape: (7, 2)
┌─────┬──────┐
│ a   ┆ b    │
│ --- ┆ ---  │
│ i64 ┆ f64  │
╞═════╪══════╡
│ 1   ┆ null │
│ 2   ┆ 1.0  │
│ 3   ┆ 1.0  │
│ 4   ┆ 3.0  │
│ 5   ┆ 3.0  │
│ 6   ┆ 5.0  │
│ 7   ┆ 5.0  │
└─────┴──────┘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants