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.fill_missing/2 to receive binary values #489

Conversation

Jhonatannunessilva
Copy link
Contributor

This PR allows the Series.fill_missing/2 function to receive binary values.

Before this PR:

iex(1)> s1 = Explorer.Series.from_list([<<1>>, <<2>>, nil, <<4>>], dtype: :binary)
#Explorer.Series<
  Polars[4]
  binary [<<1>>, <<2>>, nil, <<4>>]
>

iex(2)> Explorer.Series.fill_missing(s1, <<3>>)           
** (RuntimeError) Data types dont match: Series of dtype: Binary != Utf8
    (explorer 0.6.0-dev) lib/explorer/polars_backend/shared.ex:26: Explorer.PolarsBackend.Shared.apply_series/3

iex(2)> Explorer.Series.fill_missing(s1, <<239, 191, 19>>)
** (ArgumentError) argument error
    (explorer 0.6.0-dev) Explorer.PolarsBackend.Native.s_fill_missing_with_bin(%Inspect.Error{message: "got FunctionClauseError with message \"no function clause matching in Explorer.PolarsBackend.Shared.apply_series/3\" while inspecting %{__struct__: Explorer.PolarsBackend.Series, resource: #Reference<0.2258451173.2643591206.140034>}"}, <<239, 191, 19>>)
    (explorer 0.6.0-dev) lib/explorer/polars_backend/shared.ex:23: Explorer.PolarsBackend.Shared.apply_series/3

# Mixing string series with binary:
iex(2)> s2 = Explorer.Series.from_list(["1", "2", nil, "4"])
#Explorer.Series<
  Polars[4]
  string ["1", "2", nil, "4"]
>

iex(3)> Explorer.Series.fill_missing(s2, <<3>>)
#Explorer.Series<
  Polars[4]
  string ["1", "2", <<3>>, "4"]
>

iex(4)> Explorer.Series.fill_missing(s2, <<239, 191, 19>>)
** (ArgumentError) argument error
    (explorer 0.6.0-dev) Explorer.PolarsBackend.Native.s_fill_missing_with_bin(%Inspect.Error{message: "got FunctionClauseError with message \"no function clause matching in Explorer.PolarsBackend.Shared.apply_series/3\" while inspecting %{__struct__: Explorer.PolarsBackend.Series, resource: #Reference<0.2258451173.2643591206.140036>}"}, <<239, 191, 19>>)
    (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>>, <<2>>, nil, <<4>>], dtype: :binary)
#Explorer.Series<
  Polars[4]
  binary [<<1>>, <<2>>, nil, <<4>>]
>

iex(2)> Explorer.Series.fill_missing(s1, <<3>>)
#Explorer.Series<
  Polars[4]
  binary [<<1>>, <<2>>, <<3>>, <<4>>]
>

iex(3)> Explorer.Series.fill_missing(s1, <<239, 191, 19>>)
#Explorer.Series<
  Polars[4]
  binary [<<1>>, <<2>>, <<239, 191, 19>>, <<4>>]
>

# Mixing string series with binary:
iex(4)> s2 = Explorer.Series.from_list(["1", "2", nil, "4"])
#Explorer.Series<
  Polars[4]
  string ["1", "2", nil, "4"]
>

iex(5)> Explorer.Series.fill_missing(s2, <<3>>)
#Explorer.Series<
  Polars[4]
  string ["1", "2", <<3>>, "4"]
>

iex(6)> Explorer.Series.fill_missing(s2, <<239, 191, 19>>)
** (RuntimeError) cannot cast to string
    (explorer 0.6.0-dev) lib/explorer/polars_backend/shared.ex:26: Explorer.PolarsBackend.Shared.apply_series/3

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.

Cool! Thank you, @Jhonatannunessilva! :shipit:

@philss philss merged commit 205b78d into elixir-explorer:main Jan 30, 2023
@josevalim
Copy link
Member

Btw, thank you for the PRs @Jhonatannunessilva! If you want to contribute any other feature and you have questions, feel free to reach out! ❤️

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