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(rust): add decimal chunked comparison support #11066

Conversation

joe-stifler
Copy link

I noticed that there is no comparison support for the Decimal(precision, scale) chunked. So this PR adds that.

Changes:

  • Implement ChunkCompare for DecimalChunked.
  • Only decimals with the same precision and scale are valid for comparison.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature rust Related to Rust Polars labels Sep 12, 2023
@joe-stifler
Copy link
Author

First contribution... and I've been using polars only as a user. So apologies for any misconceptions.

@orlp
Copy link
Collaborator

orlp commented Sep 12, 2023

I think this implementation is incorrect when the scale and precision are not equal.

@joe-stifler
Copy link
Author

I think this implementation is incorrect when the scale and precision are not equal.

@orlp thanks for the comment. I agree with you. Requiring both decimals to have the same precision and scale is unnecessarily restrictive. After all, we have fixed-point data. But two notes regarding that:

  1. The restriction of comparing only decimals with the same precision and scale happens in the arrow2 library. So maybe we should fix this restriction there, not here?

image

  1. I decided not to tackle this restriction here to be consistent with the behavior of the arithmetic operations. From the following screenshot, you can see that we get errors when we try to add two decimals with different precision, even though the results don't overflow.

image

In summary, I'd be inclined to add the proper comparison between decimals of different precision/scale in the arrow2 library, as the comparison is applied there. But if this is not a good idea, I can try to also coerce_lhs_rhs to decimals with compatible types, although this opens some room for other issues (we need to rescale one of the decimals, or both, to a proper precision/scale that avoids overflow).

In any case, if you prefer to have this restriction for now, I'd like to return an error when precision/scale mismatch: Arrays must have the same precision and scale. In the end, this restriction, although not ideal, should already allow comparisons between decimals.

Please, let me know your thoughts regarding that.

@orlp
Copy link
Collaborator

orlp commented Sep 13, 2023

I believe our intention is to rely less and less on arrow2 for computation. Perhaps @ritchie46 can chime in?

@ritchie46
Copy link
Member

I believe our intention is to rely less and less on arrow2 for computation. Perhaps @ritchie46 can chime in?

Yes, that should all be handled in polars.

@stinodego
Copy link
Member

stinodego commented Jan 16, 2024

Ref #12118

Thanks for the initiative on this issue. For now, I will close this PR as it hasn't been updated in a while, and the implementation is not complete. Plus it lacks tests implemented on the Python side.

If you want to pick this back up, feel free to rebase and re-open this PR to continue working on it. The issue is still very much relevant.

@stinodego stinodego closed this Jan 16, 2024
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 rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants