Skip to content

Commit

Permalink
Add error about fill_missing/2 with decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
philss committed Oct 7, 2024
1 parent 1cd450c commit 32c3478
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/explorer/backend/series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Explorer.Backend.Series do
| Time.t()
| NaiveDateTime.t()
| Explorer.Duration.t()
| Decimal.t()

@type non_finite :: Explorer.Series.non_finite()
@type option(type) :: type | nil
Expand Down
1 change: 1 addition & 0 deletions lib/explorer/polars_backend/native.ex
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ defmodule Explorer.PolarsBackend.Native do
def s_fill_missing_with_atom(_s, _value), do: err()
def s_fill_missing_with_date(_s, _value), do: err()
def s_fill_missing_with_datetime(_s, _value), do: err()
def s_fill_missing_with_decimal(_s, _value), do: err()
def s_greater(_s, _rhs), do: err()
def s_greater_equal(_s, _rhs), do: err()
def s_head(_s, _length), do: err()
Expand Down
2 changes: 2 additions & 0 deletions lib/explorer/polars_backend/series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ defmodule Explorer.PolarsBackend.Series do
is_boolean(value) -> :s_fill_missing_with_boolean
is_struct(value, Date) -> :s_fill_missing_with_date
is_struct(value, NaiveDateTime) -> :s_fill_missing_with_datetime
is_struct(value, Decimal) -> :s_fill_missing_with_decimal
true -> raise "cannot fill missing with value: #{inspect(value)}"
end

Shared.apply_series(series, operation, [value])
Expand Down
2 changes: 2 additions & 0 deletions lib/explorer/series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4506,6 +4506,8 @@ defmodule Explorer.Series do
defp cast_to_ordered_series({:duration, _}, %Explorer.Duration{}),
do: :duration

defp cast_to_ordered_series({:decimal, _precision, _scale} = decimal, %Decimal{}), do: decimal

defp cast_to_ordered_series(_dtype, _value),
do: nil

Expand Down
20 changes: 18 additions & 2 deletions native/explorer/src/series.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
datatypes::{
ExCorrelationMethod, ExDate, ExNaiveDateTime, ExRankMethod, ExSeriesDtype, ExTime,
ExTimeUnit, ExValidValue,
ExCorrelationMethod, ExDate, ExDecimal, ExNaiveDateTime, ExRankMethod, ExSeriesDtype,
ExTime, ExTimeUnit, ExValidValue,
},
encoding, ExDataFrame, ExSeries, ExplorerError,
};
Expand Down Expand Up @@ -559,6 +559,22 @@ pub fn s_fill_missing_with_boolean(
Ok(ExSeries::new(s))
}

#[rustler::nif(schedule = "DirtyCpu")]
pub fn s_fill_missing_with_decimal(
_series: ExSeries,
_decimal: ExDecimal,
) -> Result<ExSeries, ExplorerError> {
// We need to make sure that the series dtype is aligned with the decimal's scale.
// let s = series
// .decimal()?
// .fill_null_with_values(decimal.signed_coef())?
// .into_series();
// Ok(ExSeries::new(s))
Err(ExplorerError::Other(
"fill_missing/2 with decimals is not supported yet by Polars".to_string(),
))
}

#[rustler::nif(schedule = "DirtyCpu")]
pub fn s_window_sum(
series: ExSeries,
Expand Down

0 comments on commit 32c3478

Please sign in to comment.