Coder Social home page Coder Social logo

marcogorelli / polars-plugins-tutorial Goto Github PK

View Code? Open in Web Editor NEW
93.0 3.0 10.0 2.15 MB

How you (yes, you!) can write a Polars Plugin

Home Page: https://marcogorelli.github.io/polars-plugins-tutorial/

License: MIT License

Python 54.56% Rust 43.53% Makefile 1.91%
polars

polars-plugins-tutorial's Introduction

polars-plugins-tutorial's People

Contributors

condekind avatar erichutchins avatar jacksonriley avatar kathleenhang avatar marcogorelli avatar thomasjpfan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

polars-plugins-tutorial's Issues

Add example on how to do rolling calculations with time strings

It would be awesome to add some examples on how to efficiently do something like polars does with rolling_mean_by where you can take in a string, for example 30d and a datetime column and do the rolling calculation on a time window instead of simply a certain number of rows.

Add example for plugin with state

Hello,

I am not sure if it is in the scope of the tutrial, but I think example of stateful plugin will be nice.
For instance, StringIndexer object that has two methods:

  • fit: works on a dataframe with a string column, and save a mapping between every unique string to index.
  • transform: works on a dataframe string cloumn, and transform every string value in the column to its corresponding index.

Similar to Spark's API.

Thanks!

simpler crate example

this is way too complex and to most people probably uninteresting. perhaps try snowball stemmer?

add more types to the list example

it currently reads

binary_amortized_elementwise(values, weights, |values_inner, weights_inner| {

can we add types to values_inner and weights_inner to make it easier to understand? they should just be Series

Add example of generic List as input and output

For instance,

Suppose I want to take a DataFrame that contains column with a List of numbers, and returns a new List with all the non-zero elements indices.

Input example:

┌───────────┐
│ dense     │
│ ---       │
│ list[i64] │
╞═══════════╡
│ [0, 9]    │
│ [8, 6]    │
│ [3, 3]    │
└───────────┘

Output example:

┌───────────┬────────────────┐
│ dense     ┆ sparse_indices │
│ ---       ┆ ---            │
│ list[i64] ┆ list[i64]      │
╞═══════════╪════════════════╡
│ [0, 9]    ┆ [1]            │
│ [8, 6]    ┆ [0, 1]         │
│ [3, 3]    ┆ [0, 1]         │
└───────────┴────────────────┘

Produced with this code:

df = df.with_columns(
    pl.col('dense').map_elements(lambda l: [i for i, v in enumerate(l) if v != 0]).alias('sparse_indices')
)

I know it can be solved with an index and explode, but it's pretty non-trivial code.

Thanks.

Typo in `aggregate.md`?

Should this line in docs/aggregate.md change from [0] to [1]?

#[polars_expr(output_type=Float64)]
fn vertical_weighted_mean(inputs: &[Series]) -> PolarsResult<Series> {
    let values = &inputs[0].f64()?;
-    let weights = &inputs[0].f64()?;
+    let weights = &inputs[1].f64()?;

commented out code in cookie cutter utils.rs references verstion 37.0

I just noticed that the plugin cookiecutter has commented out code for a function that accepts two columns, and it references an older version than the rest of the polars dependencies in the Cargo.toml (0.41.2). Figured it was worth mentioning.

// and make sure you have
//
// polars-arrow = { version = "0.37.0", default-features = false }
// polars-core = { version = "0.37.0", default-features = false }
//
// in your Cargo.toml file.

Set Polars>=1.3.0 as minimum version

Since we're using the pyo3_polars allocator, we need to make Polars>=1.3.0 the minimum required python-Polars version

So, the task is:

add essential Rust background

  • printing 'hello world'
  • variable assignment, mutability
  • options and results
  • vectors and iteration
  • strings, allocations, ownership? too hard to teach exhaustively, but can show basics and link?

Add to Polars Plugin Introduction - Definition, Outcome

Having a brief introductory outline could be helpful for readers who are entirely new to Polars and plugins to know what to expect.

It can look something like:

What's a Polars plugin?

Plugins let you extend Polars with your own features to create a custom dataframe experience.

What you'll learn 

After you've completed this tutorial, you'll be able to:

  • Boom
  • Boom
  • Boom

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.