Skip to content

Commit

Permalink
Using default backend in case it's not available
Browse files Browse the repository at this point in the history
There is no way to test that scenario today.
  • Loading branch information
philss committed Apr 19, 2024
1 parent 3a8d825 commit c708f46
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/explorer/backend/lazy_series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Explorer.Backend.LazySeries do
"""
alias Explorer.Series
alias Explorer.Backend
require Logger

@behaviour Explorer.Backend.Series

Expand Down Expand Up @@ -213,7 +214,6 @@ defmodule Explorer.Backend.LazySeries do
defp backend_from_args(args) do
Enum.find(args, fn
%__MODULE__{} = arg -> arg.backend
%module{} -> module
_other -> nil
end)
end
Expand Down Expand Up @@ -1196,15 +1196,28 @@ defmodule Explorer.Backend.LazySeries do
@impl true
def re_named_captures(series, pattern) do
lazy_s = lazy_series!(series)
backend = lazy_s.backend

target_dtype = backend.re_dtype(pattern)
target_dtype = get_backend(lazy_s).re_dtype(pattern)

data = new(:re_named_captures, [lazy_s, pattern], target_dtype)

Backend.Series.new(data, target_dtype)
end

defp get_backend(%__MODULE__{} = lazy_series) do
lazy_series.backend || warning_with_default_backend()
end

defp warning_with_default_backend do
backend = Explorer.Backend.get()

Logger.warning(
"cannot get backend from LazySeries. Using the default one: #{inspect(backend)}"
)

:"#{backend}.DataFrame"
end

@remaining_non_lazy_operations [
at: 2,
at_every: 2,
Expand Down

0 comments on commit c708f46

Please sign in to comment.