Skip to content

Commit

Permalink
feat: define polars_to_vega
Browse files Browse the repository at this point in the history
Little work to do, but we do need to remove NaNs as vega does not
support them.
  • Loading branch information
doudou committed Oct 8, 2024
1 parent 59a2855 commit b393c30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/syskit/log/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,11 @@ def roby_vega_task_timeline_data(*tasks)
end
end

# Convert a Daru frame into a vega data array
def polars_to_vega(frame)
frame.fill_nan(nil).to_a
end

# Convert a Daru frame into a vega data array
def daru_to_vega(frame, every: 1)
data = []
Expand Down
14 changes: 14 additions & 0 deletions test/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,20 @@ def assert_polars_frame_near(expected, actual)
end
end

describe "polars_to_vega" do
before do
@context = make_context
end

it "converts NaN into nil" do
frame = ::Polars::DataFrame.new(
{ "a" => [Float::NAN, 0.1] }, schema: nil
)
vega = @context.polars_to_vega(frame)
assert_equal [{ "a" => nil }, { "a" => 0.1 }], vega
end
end

describe "daru_to_vega" do
before do
@context = make_context
Expand Down

0 comments on commit b393c30

Please sign in to comment.