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

NIF Panic with duplicated key in rename #848

Closed
pcapel opened this issue Feb 7, 2024 · 2 comments · Fixed by #850
Closed

NIF Panic with duplicated key in rename #848

pcapel opened this issue Feb 7, 2024 · 2 comments · Fixed by #850

Comments

@pcapel
Copy link
Contributor

pcapel commented Feb 7, 2024

Overview

It's a nit pick, but a NIF panic is a surprising error when a key is duplicated in the DataFrame.rename function. A more descriptive error would make a lot of sense.

It looks like there already some validation where this could fit in, happy to add support if this is deemed worthwhile.

Minimal reproduction via the livebook below.

Reproduce Panic

Mix.install([
  {:explorer, "~> 0.8.0"}
])

Section

alias Explorer.DataFrame, as: DF
require Explorer.DataFrame
Explorer.DataFrame
DF.new(%{key1: [1, 2, 3, 4], key2: [5, 6, 7, 8]})
|> DF.rename(
  key1: "first_key",
  key1: "second_key"
)
@pcapel
Copy link
Contributor Author

pcapel commented Feb 7, 2024

I see that the linked function is for the rename which is acting against all columns. The reproduction would use the other clause, which is where the check would need to happen. Thinking something similar to maybe_raise_column_not_found?

@billylanchantin
Copy link
Contributor

billylanchantin commented Feb 7, 2024

I agree we should validate before we pass off to Polars.

Old contents

Also, I think there's a bug in the validation code?

https://github.com/elixir-explorer/explorer/blob/main/lib/explorer/shared.ex#L225-L234

This

unless Map.has_key?(df.dtypes, name) do
#                   ^^^^^^^^^

should be

unless Map.has_key?(df.names, name) do
#                   ^^^^^^^^

right?

EDIT: No I was wrong about there maybe being a bug.

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 a pull request may close this issue.

2 participants