Skip to content

Commit

Permalink
Bump Polars 0.37
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarthee committed Feb 16, 2024
1 parent 8e6546b commit 64233ca
Show file tree
Hide file tree
Showing 12 changed files with 425 additions and 255 deletions.
1 change: 0 additions & 1 deletion datasets/iris.csv
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,3 @@ sepal_length,sepal_width,petal_length,petal_width,species
6.5,3.0,5.2,2.0,Iris-virginica
6.2,3.4,5.4,2.3,Iris-virginica
5.9,3.0,5.1,1.8,Iris-virginica

14 changes: 10 additions & 4 deletions lib/explorer/series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1274,13 +1274,19 @@ 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
categories = categories |> distinct() |> cast(:category)
apply_series(series, :categorise, [categories])
end

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: apply_series(series, :categorise, [from_list(categories, dtype: :category)])

# Slice and dice

Expand Down Expand Up @@ -2086,7 +2092,7 @@ 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()
Expand Down
Loading

0 comments on commit 64233ca

Please sign in to comment.