Skip to content

Commit

Permalink
Update lib/explorer/series.ex
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim authored Feb 1, 2024
1 parent 654f913 commit 6503d1f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/explorer/series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6044,36 +6044,35 @@ defmodule Explorer.Series do
end

@doc """
Converts a string series containing valid json to a series.
Decodes a string series containing valid JSON according to `dtype`.
## Examples
iex> s = Series.from_list(["{\\"a\\":1}"])
iex> Series.json_decode(s, {:struct, %{"a" => {:s, 64}}})
#Explorer.Series<
Polars[1]
struct[1] [%{"a" => 1}]
>
iex> s = Series.from_list(["1"])
iex> Series.json_decode(s, {:s, 64})
#Explorer.Series<
Polars[1]
s64 [1]
>
Will raise `RuntimeError` if the string is invalid json.
Decoded value will be nil incase of a dtype mismatch e.g. string and integer.
iex> s = Series.from_list(["{\\"a\\":1}"])
iex> Series.json_decode(s, {:struct, %{"a" => {:s, 64}}})
#Explorer.Series<
Polars[1]
struct[1] [%{"a" => 1}]
>
## Examples
If the decoded value does not match the given `dtype`,
nil is returned for the given entry:
iex> s = Series.from_list(["\\"1\\""])
iex> Series.json_decode(s, {:s, 64})
#Explorer.Series<
Polars[1]
s64 [nil]
>
It raises an exception if the string is invalid JSON.
"""
@doc type: :string_wise
@spec json_decode(Series.t(), dtype()) :: Series.t()
Expand Down

0 comments on commit 6503d1f

Please sign in to comment.