diff --git a/lib/explorer/series.ex b/lib/explorer/series.ex index 61ad6f93b..0a4dfab94 100644 --- a/lib/explorer/series.ex +++ b/lib/explorer/series.ex @@ -3901,6 +3901,7 @@ defmodule Explorer.Series do do: {:f, 64} defp cast_to_ordered_series(:date, %Date{}), do: :date + defp cast_to_ordered_series(:time, %Time{}), do: :time defp cast_to_ordered_series({:datetime, _}, %NaiveDateTime{}), do: {:datetime, :microsecond} @@ -3909,6 +3910,9 @@ defmodule Explorer.Series do when is_integer(value), do: :integer + defp cast_to_ordered_series({:duration, _}, %Explorer.Duration{}), + do: :duration + defp cast_to_ordered_series(_dtype, _value), do: nil @@ -5470,8 +5474,13 @@ defmodule Explorer.Series do """ @doc type: :list_wise @spec member?(Series.t(), Explorer.Backend.Series.valid_types()) :: Series.t() - def member?(%Series{dtype: {:list, _}} = series, value), - do: apply_series(series, :member?, [value]) + def member?(%Series{dtype: {:list, dtype}} = series, value) do + if cast_to_comparable_series(dtype, value) do + apply_series(series, :member?, [value]) + else + dtype_mismatch_error("member?/2", series, value) + end + end def member?(%Series{dtype: dtype}, _value), do: dtype_error("member?/2", dtype, [{:list, :_}]) diff --git a/test/explorer/series_test.exs b/test/explorer/series_test.exs index 89e8e08b0..25f65e430 100644 --- a/test/explorer/series_test.exs +++ b/test/explorer/series_test.exs @@ -4483,6 +4483,7 @@ defmodule Explorer.SeriesTest do series = Series.from_list([[1.0], [1.0, 2.0]]) assert series |> Series.member?(2.0) |> Series.to_list() == [false, true] + assert series |> Series.member?(2) |> Series.to_list() == [false, true] end test "works with booleans" do