-
Notifications
You must be signed in to change notification settings - Fork 126
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
Bump Polars 0.37 #861
Bump Polars 0.37 #861
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1274,13 +1274,33 @@ defmodule Explorer.Series do | |
|
||
""" | ||
@doc type: :element_wise | ||
def categorise(%Series{dtype: l_dtype} = series, %Series{dtype: dtype} = categories) | ||
when K.and(K.in(l_dtype, [:string | @integer_types]), K.in(dtype, [:string, :category])), | ||
def categorise(%Series{dtype: l_dtype} = series, %Series{dtype: :category} = categories) | ||
when K.in(l_dtype, [:string | @integer_types]), | ||
do: apply_series(series, :categorise, [categories]) | ||
|
||
def categorise(%Series{dtype: l_dtype} = series, %Series{dtype: :string} = categories) | ||
when K.in(l_dtype, [:string | @integer_types]) do | ||
if nil_count(categories) != 0, | ||
do: | ||
raise( | ||
ArgumentError, | ||
"categories as strings cannot have nil values" | ||
) | ||
|
||
if count(categories) != n_distinct(categories), | ||
do: | ||
raise( | ||
ArgumentError, | ||
"categories as strings cannot have duplicated values" | ||
) | ||
lkarthee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
categories = cast(categories, :category) | ||
apply_series(series, :categorise, [categories]) | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved string series and list of strings categorise to here.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think we should do this because we are mapping indexes into the list. If you remove duplicates, the indexes are shifted, and the result changes. Is there a reason we removed the Rust code responsible for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. https://pola.rs/posts/polars-string-type/ This caused errors in Series.categorise and encoding of strings/binary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hit a wall with getting RevMapping to work in Series.Categorise - so tried if it can be fixed in elixir There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can do it in Elixir, but we need to get the unique_count and raise if different than size, and the nil count and raise. |
||
def categorise(%Series{dtype: l_dtype} = series, [head | _] = categories) | ||
when K.and(K.in(l_dtype, [:string | @integer_types]), is_binary(head)), | ||
do: apply_series(series, :categorise, [from_list(categories, dtype: :string)]) | ||
do: categorise(series, from_list(categories, dtype: :string)) | ||
|
||
# Slice and dice | ||
|
||
|
@@ -2086,13 +2106,20 @@ defmodule Explorer.Series do | |
iex> s1 = Explorer.Series.from_list([<<1>>, <<239, 191, 19>>], dtype: :binary) | ||
iex> s2 = Explorer.Series.from_list([<<3>>, <<4>>], dtype: :binary) | ||
iex> Explorer.Series.format([s1, s2]) | ||
** (RuntimeError) Polars Error: invalid utf-8 sequence | ||
** (RuntimeError) Polars Error: invalid utf8 | ||
""" | ||
@doc type: :shape | ||
@spec format([Series.t() | String.t()]) :: Series.t() | ||
def format([_ | _] = list) do | ||
list = cast_to_string(list) | ||
impl!(list).format(list) | ||
|
||
if impl = impl!(list) do | ||
impl.format(list) | ||
else | ||
[hd | rest] = list | ||
s = Series.from_list([hd], dtype: :string) | ||
impl!([s]).format([s | rest]) | ||
end | ||
end | ||
|
||
defp cast_to_string(list) do | ||
|
@@ -2103,8 +2130,8 @@ defmodule Explorer.Series do | |
%Series{} = s -> | ||
cast(s, :string) | ||
|
||
value when is_binary(value) -> | ||
from_list([value], dtype: :string) | ||
value when K.or(is_binary(value), K.is_nil(value)) -> | ||
value | ||
|
||
other -> | ||
raise ArgumentError, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line is causing an extra row to be added to data frame and its related tests are failing..