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

feat: Implement merge_sorted for binary #21045

Merged
merged 2 commits into from
Feb 4, 2025

Conversation

mcrumiller
Copy link
Contributor

@mcrumiller mcrumiller commented Feb 2, 2025

Quite trivial, closes #20988

import polars as pl

df1 = pl.DataFrame({
    "a": pl.Series("a", [b"1", b"3", b"5"], pl.Binary()),
    "b": [1, 3, 5],
})
df2 = pl.DataFrame({
    "a": pl.Series("a", [b"2", b"4", b"6"], pl.Binary()),
    "b": [2, 4, 6],
})

print(df1.merge_sorted(df2, "a"))
# shape: (6, 2)
# ┌────────┬─────┐
# │ a      ┆ b   │
# │ ---    ┆ --- │
# │ binary ┆ i64 │
# ╞════════╪═════╡
# │ b"1"   ┆ 1   │
# │ b"2"   ┆ 2   │
# │ b"3"   ┆ 3   │
# │ b"4"   ┆ 4   │
# │ b"5"   ┆ 5   │
# │ b"6"   ┆ 6   │
# └────────┴─────┘

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Feb 2, 2025
Copy link

codecov bot commented Feb 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.27%. Comparing base (1678638) to head (9d33c26).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21045      +/-   ##
==========================================
- Coverage   79.27%   79.27%   -0.01%     
==========================================
  Files        1583     1585       +2     
  Lines      225549   225624      +75     
  Branches     2586     2588       +2     
==========================================
+ Hits       178810   178865      +55     
- Misses      46149    46169      +20     
  Partials      590      590              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mcrumiller mcrumiller marked this pull request as ready for review February 3, 2025 00:55
@@ -157,6 +157,12 @@ fn series_to_merge_indicator(lhs: &Series, rhs: &Series) -> Vec<bool> {

get_merge_indicator(lhs.into_iter(), rhs.into_iter())
},
DataType::Binary => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you dispatch String via binary as well? That saves an extra monomorphization.

Copy link
Contributor Author

@mcrumiller mcrumiller Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -152,14 +152,18 @@ fn series_to_merge_indicator(lhs: &Series, rhs: &Series) -> Vec<bool> {
get_merge_indicator(lhs.into_iter(), rhs.into_iter())
},
DataType::String => {
let lhs = lhs_s.str().unwrap();
let rhs = rhs_s.str().unwrap();
// SAFETY: String to Binary is valid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need unsafe nor casts here:

            let lhs = lhs.str().unwrap().as_binary();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh ok. Fixed.

@ritchie46 ritchie46 merged commit 5d3fd07 into pola-rs:main Feb 4, 2025
25 of 27 checks passed
@mcrumiller mcrumiller deleted the merge-sorted-binary branch February 4, 2025 18:54
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 python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge sorted not implemented for binary
2 participants