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

fix: zip_with also broadcast mask #12309

Merged
merged 3 commits into from
Nov 8, 2023
Merged

fix: zip_with also broadcast mask #12309

merged 3 commits into from
Nov 8, 2023

Conversation

reswqa
Copy link
Collaborator

@reswqa reswqa commented Nov 8, 2023

Per discuss in discord, and It seems that all test can be passed.

@reswqa reswqa changed the title CI Test fix: zip_with also broadcast mask Nov 8, 2023
@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Nov 8, 2023
@reswqa reswqa marked this pull request as ready for review November 8, 2023 07:14
@ritchie46
Copy link
Member

Well... That was easy! 😄

@ritchie46
Copy link
Member

@reswqa shall we take this opportunity to write it via ternary_elementwise. Those will be better optimized.

@reswqa
Copy link
Collaborator Author

reswqa commented Nov 8, 2023

shall we take this opportunity to write it via ternary_elementwise.

@ritchie46 As for the impl_ternary_broadcast branch, I guess we only need apply and binary_elementwise.

When I tried to do this, I ran into lifecycle issues with utf8/binary types.

Take the following as example:

(l_len, 1, mask_len) if l_len == mask_len => {
            let right = $other.get(0);
            let val:ChunkedArray<$ty> = binary_elementwise($mask, $self, |mask:Option<bool>, left|{
                ternary_apply(mask.unwrap_or(false), left, right)
             }).with_name($self.name());
            Ok(val)
},
error: implementation of `FnOnce` is not general enough
   --> crates/polars-core/src/chunked_array/ops/zip.rs:76:41
    |
76  |               let val:ChunkedArray<$ty> = binary_elementwise($mask, $self, |mask:Option<bool>, left|{
    |  _________________________________________^
77  | |                 ternary_apply(mask.unwrap_or(false), left, right)
78  | |              }).with_name($self.name());
    | |_______________^ implementation of `FnOnce` is not general enough
...
174 | /             impl_ternary_broadcast!(
175 | |                 self,
176 | |                 self.len(),
177 | |                 other.len(),
...   |
183 | |             )
    | |_____________- in this macro invocation
    |
    = note: closure with signature `fn(std::option::Option<bool>, std::option::Option<&'2 [u8]>) -> std::option::Option<&[u8]>` must implement `FnOnce<(std::option::Option<bool>, std::option::Option<&'1 [u8]>)>`, for any lifetime `'1`...
    = note: ...but it actually implements `FnOnce<(std::option::Option<bool>, std::option::Option<&'2 [u8]>)>`, for some specific lifetime `'2`

@cmdlineluser
Copy link
Contributor

I ran into lifecycle issues

I think that's the same issue I ran into.

@orlp showed me how to fix: #12071 (comment)

@ritchie46
Copy link
Member

@reswqa I think we can follow up with the improvement on a second PR. This PR is the fix. Would love to see if we can make it better with proper column traversal. :)

@ritchie46 ritchie46 merged commit 81b02f3 into pola-rs:main Nov 8, 2023
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants