Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to convert between jagged arrays and frames #532

Merged
merged 5 commits into from
Jul 25, 2021
Merged

Add functions to convert between jagged arrays and frames #532

merged 5 commits into from
Jul 25, 2021

Conversation

kMutagene
Copy link
Member

Content

This PR adds functions to:

  • Create frames from jagged arrays:
    • FromJaggedArray for C#, ofJaggedArray for F#
  • Convert frames to jagged arrays:
    • static members toJaggedArray<'R> for any type of conversion for the frame data (returns 'R[][])
    • function Frame.toJaggedArray to return a float [][] analogously to Frame.ToArray2D
  • I also added tests the same way they work for the Array2D functions, as well as a test that compares frames from an Array2D and a jagged array with the same data.

Why?

These are simply convenience functions that improve interop with Plotly.NET. I often handle data frames with numeric values only, where i want to visualize the contents after some transformations with Deedle. Charts that accept two-dimensional data in Plotly.NET expect data as jagged arrays, so i would love to see this added as it prevents a clunky conversion step from the Array2D obtained by Frame.ToArray2D and the chart initialization.

additional notes

The build fails for me with an outdated log format, so i updated build dependencies and fake as well, if that breaks anything please let me know.

@kMutagene kMutagene changed the title Update build dependencies to prevent log file error Add functions to convert between jagged arrays and frames Jul 25, 2021
invalidOp "FromJaggedArray: The input jagged array must have the same dimensions in all inner arrays."
else
let arr2D = Array2D.init jArray.Length jArray.[0].Length (fun r c -> jArray.[r].[c])
Frame.FromArray2D(arr2D)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creating a frame like that doesn't look effective . We create a copy of array just to pass it further? We can easily do the same even now

jArray |> array2D |> Frame.FromArray2D

Copy link
Member Author

@kMutagene kMutagene Jul 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not thinking about performance here, as I see the frame creation as a step that only happens a single time in a data analysis pipeline, but i can definitely adjust this to work exactly as the FromArray2D function.

We can easily do the same even now
jArray |> array2D |> Frame.FromArray2D

Agreed, but the whole point of this PR is to get rid of the function in the middle. And where is the array2D from this example coming from anyways? I cant find it in FSharp.Core and needing an external library for that or having to do the copy in the analysis is exactly what i want to prevent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that was a brainfart on my side :D sorry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same code now that is used in FromArray2D so I think it should be now more performant either way

@zyzhu
Copy link
Contributor

zyzhu commented Jul 25, 2021

It's indeed a convenience function, especially from C# as there is no helper function array2D in C#. Thanks for your review @FoggyFinder!

@zyzhu zyzhu merged commit fe92158 into fslaborg:master Jul 25, 2021
@zyzhu
Copy link
Contributor

zyzhu commented Jul 25, 2021

@kMutagene, I've released 2.4.1. BTW, would you like to be a co-maintainer of this project? As you are the main contributor to FsLab ecosystem, it could help you to iterate faster.

@kMutagene
Copy link
Member Author

@zyzhu sure, that would be great!

@zyzhu
Copy link
Contributor

zyzhu commented Jul 26, 2021

That's great! Just added you as maintainer of the project now. I also sent you invitation on nuget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants