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 binary dtype to Series.in/2 #477

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions native/explorer/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ pub fn s_in(data: ExSeries, rhs: ExSeries) -> Result<ExSeries, ExplorerError> {
DataType::Int64 => s.i64()?.is_in(&rhs)?,
DataType::Float64 => s.f64()?.is_in(&rhs)?,
DataType::Utf8 => s.utf8()?.is_in(&rhs)?,
DataType::Binary => s.binary()?.is_in(&rhs)?,
DataType::Date => s.date()?.is_in(&rhs)?,
DataType::Datetime(_, _) => s.datetime()?.is_in(&rhs)?,
dt => panic!("is_in/2 not implemented for {dt:?}"),
Expand Down
116 changes: 116 additions & 0 deletions test/explorer/series_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,122 @@ defmodule Explorer.SeriesTest do
end
end

describe "in/2" do
test "with integer series" do
s1 = Series.from_list([1, 2, 3])
s2 = Series.from_list([1, 0, 3])

assert s1 |> Series.in(s2) |> Series.to_list() == [true, false, true]
end

test "with float series" do
s1 = Series.from_list([1.0, 2.0, 3.0])
s2 = Series.from_list([1.0, 0.0, 3.0])

assert s1 |> Series.in(s2) |> Series.to_list() == [true, false, true]
end

test "with binary series" do
s1 = Series.from_list([<<239, 191, 19>>, <<2>>, <<3>>], dtype: :binary)
s2 = Series.from_list([<<239, 191, 19>>, <<0>>, <<3>>], dtype: :binary)

assert s1 |> Series.in(s2) |> Series.to_list() == [true, false, true]
end

test "with string series" do
s1 = Series.from_list(["1", "2", "3"])
s2 = Series.from_list(["1", "0", "3"])

assert s1 |> Series.in(s2) |> Series.to_list() == [true, false, true]
end

test "with date series" do
s1 = Series.from_list([~D[2023-01-17], ~D[2023-01-18], ~D[2023-01-09]])
s2 = Series.from_list([~D[2023-01-17], ~D[2023-01-04], ~D[2023-01-09]])

assert s1 |> Series.in(s2) |> Series.to_list() == [true, false, true]
end

test "with datetime series" do
s1 =
Series.from_list([
~N[2023-01-17 20:00:56.576456Z],
~N[2023-01-18 20:30:56.576456Z],
~N[2023-01-09 21:00:56.576456Z]
])

s2 =
Series.from_list([
~N[2023-01-17 20:00:56.576456Z],
~N[2023-01-04 22:00:56.576456Z],
~N[2023-01-09 21:00:56.576456Z]
])

assert s1 |> Series.in(s2) |> Series.to_list() == [true, false, true]
end

test "with a list on the right-hand side" do
s1 = Series.from_list([1, 2, 3])
l1 = [1, 0, 3]

assert s1 |> Series.in(l1) |> Series.to_list() == [true, false, true]
end

test "with a smaller series on the right-hand side" do
s1 = Series.from_list([1, 2, 3])
s2 = Series.from_list([1, 3])

assert s1 |> Series.in(s2) |> Series.to_list() == [true, false, true]
end

test "with a bigger series on the right-hand side" do
s1 = Series.from_list([1, 2, 3])
s2 = Series.from_list([1, 3, 5, 10])

assert s1 |> Series.in(s2) |> Series.to_list() == [true, false, true]
end

test "compare integer series with a float series" do
s1 = Series.from_list([1, 2, 3])
s2 = Series.from_list([1.0, 0.5, 3.0])

assert s1 |> Series.in(s2) |> Series.to_list() == [true, false, true]
end

test "compare integer series with a string series" do
s1 = Series.from_list([1, 2, 3])
s2 = Series.from_list(["1", "0", "3"])

assert_raise ArgumentError, fn ->
Series.in(s1, s2)
end
end

test "compare string series with a binary series" do
s1 = Series.from_list(["1", "2", "3"])
s2 = Series.from_list([<<1>>, <<0>>, <<"3">>], dtype: :binary)

assert_raise ArgumentError, fn ->
Series.in(s1, s2)
end
end

test "compare date series with a datetime series" do
s1 = Series.from_list([~D[2023-01-17], ~D[2023-01-18], ~D[2023-01-09]])

s2 =
Series.from_list([
~N[2023-01-17 20:00:56.576456Z],
~N[2023-01-04 22:00:56.576456Z],
~N[2023-01-09 21:00:56.576456Z]
])

assert_raise ArgumentError, fn ->
Series.in(s1, s2)
end
end
end

describe "iotype/1" do
test "integer series" do
s = Series.from_list([1, 2, 3])
Expand Down