Skip to content
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
67 changes: 54 additions & 13 deletions lib/explorer/backend/lazy_series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,20 @@ defmodule Explorer.Backend.LazySeries do
floor: 1,
ceil: 1,
# Date functions
day_of_week: 1,
year: 1,
month: 1,
day_of_month: 1,
is_leap_year: 1,
quarter_of_year: 1,
days_of_month: 1,
day_of_year: 1,
iso_year: 1,
week_of_year: 1,
month: 1,
year: 1,
day_of_week: 1,
hour: 1,
minute: 1,
second: 1,
nanosecond: 1,
# List functions
join: 2,
lengths: 1,
Expand Down Expand Up @@ -685,8 +691,36 @@ defmodule Explorer.Backend.LazySeries do
end

@impl true
def day_of_week(%Series{} = s) do
data = new(:day_of_week, [lazy_series!(s)], {:s, 8})
def year(%Series{} = s) do
data = new(:year, [lazy_series!(s)], {:s, 32})

Backend.Series.new(data, {:s, 32})
end

@impl true
def month(%Series{} = s) do
data = new(:month, [lazy_series!(s)], {:s, 8})

Backend.Series.new(data, {:s, 8})
end

@impl true
def day_of_month(%Series{} = s) do
data = new(:day_of_month, [lazy_series!(s)], {:s, 8})

Backend.Series.new(data, {:s, 8})
end

@impl true
def is_leap_year(%Series{} = s) do
data = new(:is_leap_year, [lazy_series!(s)], :boolean)

Backend.Series.new(data, :boolean)
end

@impl true
def quarter_of_year(%Series{} = s) do
data = new(:quarter_of_year, [lazy_series!(s)], {:s, 8})

Backend.Series.new(data, {:s, 8})
end
Expand All @@ -699,24 +733,24 @@ defmodule Explorer.Backend.LazySeries do
end

@impl true
def week_of_year(%Series{} = s) do
data = new(:week_of_year, [lazy_series!(s)], {:s, 8})
def iso_year(%Series{} = s) do
data = new(:iso_year, [lazy_series!(s)], {:s, 32})

Backend.Series.new(data, {:s, 8})
Backend.Series.new(data, {:s, 32})
end

@impl true
def month(%Series{} = s) do
data = new(:month, [lazy_series!(s)], {:s, 8})
def week_of_year(%Series{} = s) do
data = new(:week_of_year, [lazy_series!(s)], {:s, 8})

Backend.Series.new(data, {:s, 8})
end

@impl true
def year(%Series{} = s) do
data = new(:year, [lazy_series!(s)], {:s, 32})
def day_of_week(%Series{} = s) do
data = new(:day_of_week, [lazy_series!(s)], {:s, 8})

Backend.Series.new(data, {:s, 32})
Backend.Series.new(data, {:s, 8})
end

@impl true
Expand All @@ -740,6 +774,13 @@ defmodule Explorer.Backend.LazySeries do
Backend.Series.new(data, {:s, 8})
end

@impl true
def nanosecond(%Series{} = s) do
data = new(:nanosecond, [lazy_series!(s)], {:s, 32})

Backend.Series.new(data, {:s, 32})
end

@impl true
def ewm_mean(%Series{} = series, alpha, adjust, min_periods, ignore_nils) do
args = [lazy_series!(series), alpha, adjust, min_periods, ignore_nils]
Expand Down
11 changes: 8 additions & 3 deletions lib/explorer/backend/series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,19 @@ defmodule Explorer.Backend.Series do

# Date / DateTime

@callback day_of_week(s) :: s
@callback year(s) :: s
@callback month(s) :: s
@callback day_of_month(s) :: s
@callback is_leap_year(s) :: s
@callback quarter_of_year(s) :: s
@callback day_of_year(s) :: s
@callback iso_year(s) :: s
@callback week_of_year(s) :: s
@callback month(s) :: s
@callback year(s) :: s
@callback day_of_week(s) :: s
@callback hour(s) :: s
@callback minute(s) :: s
@callback second(s) :: s
@callback nanosecond(s) :: s

# List
@callback join(s, String.t()) :: s
Expand Down
12 changes: 9 additions & 3 deletions lib/explorer/polars_backend/expression.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ defmodule Explorer.PolarsBackend.Expression do
coalesce: 2,
count: 1,
size: 1,
day_of_week: 1,
year: 1,
month: 1,
day_of_month: 1,
is_leap_year: 1,
quarter_of_year: 1,
days_of_month: 1,
day_of_year: 1,
iso_year: 1,
week_of_year: 1,
month: 1,
year: 1,
day_of_week: 1,
hour: 1,
minute: 1,
second: 1,
nanosecond: 1,
distinct: 1,
equal: 2,
exp: 1,
Expand Down
11 changes: 8 additions & 3 deletions lib/explorer/polars_backend/native.ex
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,19 @@ defmodule Explorer.PolarsBackend.Native do
def s_ewm_standard_deviation(_s, _alpha, _adjust, _bias, _min_periods, _ignore_nils), do: err()
def s_ewm_variance(_s, _alpha, _adjust, _bias, _min_periods, _ignore_nils), do: err()
def s_in(_s, _other), do: err()
def s_day_of_week(_s), do: err()
def s_year(_s), do: err()
def s_month(_s), do: err()
def s_day_of_month(_s), do: err()
def s_is_leap_year(_s), do: err()
def s_quarter_of_year(_s), do: err()
def s_day_of_year(_s), do: err()
def s_iso_year(_s), do: err()
def s_week_of_year(_s), do: err()
def s_month(_s), do: err()
def s_year(_s), do: err()
def s_day_of_week(_s), do: err()
def s_hour(_s), do: err()
def s_minute(_s), do: err()
def s_second(_s), do: err()
def s_nanosecond(_s), do: err()
def s_sin(_s), do: err()
def s_cos(_s), do: err()
def s_tan(_s), do: err()
Expand Down
36 changes: 28 additions & 8 deletions lib/explorer/polars_backend/series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -755,24 +755,40 @@ defmodule Explorer.PolarsBackend.Series do

# Date / DateTime
@impl true
def day_of_week(series),
do: Shared.apply_series(series, :s_day_of_week)
def year(series),
do: Shared.apply_series(series, :s_year)

@impl true
def month(series),
do: Shared.apply_series(series, :s_month)

@impl true
def day_of_month(series),
do: Shared.apply_series(series, :s_day_of_month)

@impl true
def is_leap_year(series),
do: Shared.apply_series(series, :s_is_leap_year)

@impl true
def quarter_of_year(series),
do: Shared.apply_series(series, :s_quarter_of_year)

@impl true
def day_of_year(series),
do: Shared.apply_series(series, :s_day_of_year)

@impl true
def week_of_year(series),
do: Shared.apply_series(series, :s_week_of_year)
def iso_year(series),
do: Shared.apply_series(series, :s_iso_year)

@impl true
def month(series),
do: Shared.apply_series(series, :s_month)
def week_of_year(series),
do: Shared.apply_series(series, :s_week_of_year)

@impl true
def year(series),
do: Shared.apply_series(series, :s_year)
def day_of_week(series),
do: Shared.apply_series(series, :s_day_of_week)

@impl true
def hour(series),
Expand All @@ -786,6 +802,10 @@ defmodule Explorer.PolarsBackend.Series do
def second(series),
do: Shared.apply_series(series, :s_second)

@impl true
def nanosecond(series),
do: Shared.apply_series(series, :s_nanosecond)

# Lists

@impl true
Expand Down
Loading
Loading