-
Notifications
You must be signed in to change notification settings - Fork 123
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
Allows Series functions to receive nan, infinity, and neg_infinity values #512
Allows Series functions to receive nan, infinity, and neg_infinity values #512
Conversation
- This function now accepts :nan, :infinity, and :neg_infinity when the Series has a numerical dtype
- This function now accepts :nan, :infinity, and :neg_infinity when the Series has a numerical dtype
- This function now accepts :nan, :infinity, and :neg_infinity values
- This function now accepts :nan, :infinity, and :neg_infinity values
- This function now accepts :nan, :infinity, and :neg_infinity values
- This function now accepts :nan, :infinity, and :neg_infinity values
- This function now accepts :nan, :infinity, and :neg_infinity values
@@ -193,29 +193,41 @@ defmodule Explorer.PolarsBackend.Series do | |||
def add(%Series{} = left, %Series{} = right), | |||
do: Shared.apply_series(left, :s_add, [right.data]) | |||
|
|||
def add(left, right) when is_number(right), do: apply_scalar_on_rhs(:add, left, right) | |||
def add(left, right) when is_number(left), do: apply_scalar_on_lhs(:add, left, right) | |||
def add(left, right) when is_number(right) or right in [:nan, :infinity, :neg_infinity], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about using defguardp
to define this? I just can't think of a good name :D
defguardp is_numerical(n) when is_number(n) or n in [:nan, :infinity, :neg_infinity]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I thought of the name is_number?/1, but it might be confused with Elixir's is_number/1. So I think the name is_numerical/1 is probably better.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I create this guard in explorer/series.ex or polars_backend/series.ex? (It can be used in basic_numeric_operation/3 and valid_for_bool_mask_operation?/2 functions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explorer.Series. If you want to share, you can create it Utils, but it is small enough that should be fine to duplicate. We should also rename numeric_dtype?
to is_numeric_dtype
since guards have the is_
prefix instead of question marks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should I rename the io_dtype?/1, numeric_or_bool_dtype?/1, and numeric_or_date_dtype?/1 guards as well? (is_io_dtype/1, is_numeric_or_bool_dtype/1, and is_numeric_or_date_dtype/1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally yes, but since there are several, let's do that in another commit to keep this one focused. :)
Yes, we should support a series of floats too! |
💚 💙 💜 💛 ❤️ |
I merged this for now so we can unblock work on the upcoming PRs. :) |
This PR allows Series functions to receive nan, infinity, and neg_infinity values.
This is part of #467
Functions that have been tested and are working:
NOTES:
So when Series.equal/2 is called:
But with the Series.in/2 function the behavior is different: