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

Add integer typecheck guard to Series.shift #524

Merged
merged 4 commits into from
Feb 28, 2023

Conversation

blutack
Copy link
Contributor

@blutack blutack commented Feb 28, 2023

Add an integer typecheck guard to Series.shift, as discussed in issue #523.

This improves the error returned when calling Series.shift with a float or some other invalid datatype.

Before:

iex> Explorer.Series.shift(s, 1.0)
** (ArgumentError) argument error
    (explorer 0.6.0-dev) Explorer.PolarsBackend.Native.s_shift(#Explorer.PolarsBackend.Series<
  shape: (5,)
  Series: '' [i64]
  [
        1
        2
        3
        4
        5
  ]
>, 1.0)
    (explorer 0.6.0-dev) lib/explorer/polars_backend/shared.ex:23: Explorer.PolarsBackend.Shared.apply_series/3
    iex:3: (file)

After:

iex> Explorer.Series.shift(s, 1.0)
** (ArgumentError) Explorer.Series.shift/2 not implemented for dtype 1.0. Valid dtypes are [:integer]
    (explorer 0.6.0-dev) lib/explorer/series.ex:3622: Explorer.Series.dtype_error/3
    iex:3: (file)

lib/explorer/series.ex Outdated Show resolved Hide resolved
@blutack
Copy link
Contributor Author

blutack commented Feb 28, 2023

Thank you, I noticed that dtype_error shouldn't be used outside of Series arguments and changed the default function to raise a formatted error directly, but just removing the unguarded function is more sensible. Please back the second commit out if you prefer to stick with that!

The dtype_error series of functions are for use with Series arguments,
 and so the resulting message is confusing.
lib/explorer/series.ex Outdated Show resolved Hide resolved
@josevalim josevalim merged commit 03b42fb into elixir-explorer:main Feb 28, 2023
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@blutack blutack deleted the add_guard_to_shift branch March 2, 2023 09:52
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.

2 participants