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 field/2 for extracting field from struct #839

Merged
merged 3 commits into from
Jan 29, 2024

Conversation

lkarthee
Copy link
Member

iex> s = Series.from_list([%{a: 1}, %{a: 2}])
iex> Series.field(s, "a")
#Explorer.Series<
  Polars[2]
  s64 [1, 2]
>
iex> Series.field(s, "b")
* (ArgumentError) field "b" not found in fields ["a"]
    (explorer 0.9.0-dev) lib/explorer/series.ex:6041: Explorer.Series.field/2
    iex:3: (file)

iex> df = DF.new([%{a: %{n: 1}}, %{a: %{n: 1}}])
iex> DF.mutate(df, n: field(a, "n"))
#Explorer.DataFrame<
  Polars[2 x 2]
  a struct[1] [%{"n" => 1}, %{"n" => 1}]
  n s64 [1, 1]
>
iex> DF.mutate(df, n: field(a, "m"))
** (ArgumentError) field "m" not found in fields ["n"]
    (explorer 0.9.0-dev) lib/explorer/series.ex:6041: Explorer.Series.field/2
    iex:3: (file)
    iex:3: (file)

lib/explorer/series.ex Outdated Show resolved Hide resolved
Co-authored-by: José Valim <jose.valim@gmail.com>
@lkarthee lkarthee closed this Jan 28, 2024
@lkarthee
Copy link
Member Author

Mistakenly clicked some button on mobile app. Will send pr again.

@josevalim
Copy link
Member

I can reopen. Feel free to close this one if you prefer it closed. :D

@josevalim josevalim reopened this Jan 28, 2024
@lkarthee
Copy link
Member Author

I prefer a merge :D

I need few struct features for migrating to pure explorer workflow. I have a json column in database and I am using polars to extract the data.

  • field
  • json_decode
  • json_path_match
  • json_encode ??

One PR at a time..

@josevalim josevalim merged commit 56e6051 into elixir-explorer:main Jan 29, 2024
8 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@lkarthee lkarthee deleted the struct_field branch January 29, 2024 09:00
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