Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Add more examples for the rust #386

Merged
merged 8 commits into from
Sep 13, 2023

Conversation

Atreyagaurav
Copy link
Contributor

Closes #385

This is just me trying out some of the examples in Rust as they were lacking. I couldn't figure out how to do certain things like in python example as there weren't enough documentation (examples in docs.rs). I'd appreciate comments on things that could be done easily but I took a roundabout method, and other things.

@Atreyagaurav
Copy link
Contributor Author

I started this coz the timeseries example was super hard to do in rust because of the data types, and I somehow found a solution online that was like 10 lines of code for 1 lines in python. But after trying out and cooling off for a day, I was able to find a solution that was as short as the one in the python example. I want to add that, but I wanted to start from the basic ones so that I can learn those as well.

So, if you guys don't have anyone else working on these, and want to merge it, then I'll add more to this pull request.

@Atreyagaurav
Copy link
Contributor Author

Just found out the docs fail as the column_selections.rs is incomplete. I thought it'd just keep the rust codes when it finds the blocks and remove it when it can't.

If it needs all the blocks in a source files, then we can divide the file into two (I think the selectors part is only applicable to python, I found absolutely no content that looks the same except the ones we normally use in rust already). Or we can also keep empty code blocks just for the docs to run. But if it's fixable from some config (missing block in one language = ignore) then that might be a better idea too.

@Atreyagaurav Atreyagaurav changed the title Add expressions/{null,operators,column_selections (partial)}; Add more examples for the rust Aug 29, 2023
@stinodego
Copy link
Member

Is this ready for review? If so, please mark it as such.

I see no reason to remove the Python example here...

@Atreyagaurav
Copy link
Contributor Author

@stinodego I want to add more examples, so I'll mark it ready when I do those, I wanted to make sure it was welcome. And I was not doing something that someone else was already doing.

I haven't said anything about removing python examples, considering most people use it in python, that's what most people will want. I was just thinking if the documentation program errors out if the .rs file is missing some code blocks (try removing the commented out blocks in 2ab17bd and see the error) then maybe we can separate the said chapter into two part, one that can be done in both and one that's python specific. But I've added the comments saying it's not possible to do it in rust now, and linked the Issue so we could add those after they've been implemented in rust.

Oh If you mean the edit on .py file by "remove python example", then no worries. That block was duplicate that's why I removed it. The actual example is still there.

@Atreyagaurav Atreyagaurav marked this pull request as ready for review September 1, 2023 19:56
@Atreyagaurav
Copy link
Contributor Author

I've added examples for many chapters on expressions and then for all the chapters in transformations, including the time series subchapter.

I saw that some code blocks has requires this feature thing, should I add them for all examples? And how do I add them? Looking at the markdown, I can only see the strings for the API. Also, are those features the flag for python? Because I had to use rust features like dtype-i8/i16 to make some of the example work.

I didn't add any examples for following 3 chapters for expressions as they looked a bit complex.

  • Lists and Arrays
  • User-defined functions
  • The Struct datatype

There were a few problems that I couldn't figure out how to solve in a better way. They do work with the examples for now. I just feel like there should be better/easier ways to do them.

  • In transformations/time-series/rolling.rs, counting days from a duration column, there should be something like col(_).duration().days(), but that didn't work. So I had to use a workaround and calculate the days myself. The example on that on the python code also seems wrong on counting the number of days till EOM.
  • There is no easy way to make a date column, I had to use NaiveDate manually for all members, or if I wanted to use date_range then it needs NaiveDatetime inputs, so I had to add h,m,s information as 0,0,0 and then cast to DataType::Date at the end.
  • The explanation is for python and some of them don't apply. For example, python .cast by default errors out on overflow, but rust one makes them null. You have to use strict_cast in rust explicitly. I made the code block output the same thing as the examples, even if the explanation is for python.

@Atreyagaurav
Copy link
Contributor Author

Ended up adding examples for lists and structs as well. The solutions are sometimes as elegant in rust, but sometimes they are verbose due to the limitations of typed languages. Or maybe there are easier ways that I was not able to find.

Anyway, @stinodego it should be done now. If you know ways to make certain examples from here better, please let me know.

@stinodego
Copy link
Member

This is quite an effort! Thanks for the PR @Atreyagaurav

We currently do not have a way to validate Rust examples in this repo - will be added later. So I cannot really test all these additions. I'll just merge them for now, we can work out any issues later once validation is added.

@stinodego stinodego merged commit 4b3847a into pola-rs:master Sep 13, 2023
3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lacking Rust Examples
2 participants