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 Series.pow/2 to receive float series on both sides and negative base #514

Conversation

Jhonatannunessilva
Copy link
Contributor

@Jhonatannunessilva Jhonatannunessilva commented Feb 21, 2023

This PR allows the Series.pow/2 function to receive float series on both sides and a negative base.

This is part of #512

Before this PR:

iex(1)> s1 = Explorer.Series.from_list([1.0, 2.5, :nan, :infinity, :neg_infinity])
#Explorer.Series<
  Polars[5]
  float [1.0, 2.5, NaN, Inf, -Inf]
>

iex(2)> s2 = Explorer.Series.from_list([1.0, 3.5, :nan, :infinity, :neg_infinity])
#Explorer.Series<
  Polars[5]
  float [1.0, 3.5, NaN, Inf, -Inf]
>

iex(3)> Explorer.Series.pow(s1, s2)                                               
** (RuntimeError) Data types don't match: Series of dtype: Float64 != Int64
    (explorer 0.6.0-dev) lib/explorer/polars_backend/shared.ex:26: Explorer.PolarsBackend.Shared.apply_series/3

iex(3)> s3 = Explorer.Series.from_list([1, 2, 3])                                 
#Explorer.Series<
  Polars[3]
  integer [1, 2, 3]
>

iex(4)> Explorer.Series.pow(-2, s3)                                               
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: {error, badarg}', src/series.rs:829:54
                                                                                                                   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
                                        ** (ErlangError) Erlang error: :nif_panicked
    (explorer 0.6.0-dev) Explorer.PolarsBackend.Native.s_pow_f_lhs(#Explorer.PolarsBackend.Series<
  shape: (3,)
  Series: '' [i64]
  [
        1
        2
        3
  ]
>, -2)
    (explorer 0.6.0-dev) lib/explorer/polars_backend/shared.ex:23: Explorer.PolarsBackend.Shared.apply_series/3

After this PR:

iex(1)> s1 = Explorer.Series.from_list([1.0, 2.5, :nan, :infinity, :neg_infinity])
#Explorer.Series<
  Polars[5]
  float [1.0, 2.5, NaN, Inf, -Inf]
>

iex(2)> s2 = Explorer.Series.from_list([1.0, 3.5, :nan, :infinity, :neg_infinity])      
#Explorer.Series<
  Polars[5]
  float [1.0, 3.5, NaN, Inf, -Inf]
>

iex(3)> Explorer.Series.pow(s1, s2)
#Explorer.Series<
  Polars[5]
  float [1.0, 24.705294220065465, NaN, Inf, 0.0]
>

iex(4)> s3 = Explorer.Series.from_list([1, 2, 3])
#Explorer.Series<
  Polars[3]
  integer [1, 2, 3]
>

iex(5)> Explorer.Series.pow(-2, s3)
#Explorer.Series<
  Polars[3]
  integer [-2, 4, -8]
>

Copy link
Contributor

@philss philss left a comment

Choose a reason for hiding this comment

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

Thanks for improving the test suite! ❤️

Just a comment and :shipit:

lib/explorer/polars_backend/series.ex Outdated Show resolved Hide resolved
Jhonatannunessilva and others added 2 commits February 21, 2023 19:04
Co-authored-by: Philip Sampaio <philip.sampaio@gmail.com>
@philss philss merged commit 3d3e006 into elixir-explorer:main Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants