Skip to main content

A tool that brings type safety and type checking enhancements to the Polars library.

Project description

Polar Patch

This package provides type hinting and IDE support for plugins to the Polars package, enhancing the development experience.

Problem It Solves

Polars is a fast DataFrame library for Python, but it lacks a way to provide type hints with type checker and IDE support for custom plugins. The polars maintainers have no plans to fill this gap from within polars itself. So Summit Sailors is stepping in to help.

Motivation

With this package, developers can:

  • Write more robust and maintainable polars plugins.
  • Utilize IDE Type Checker features such as autocompletion and inline documentation.
  • Extend the polars ecosystem with more incentive to create new plugins

How does it work?

  1. PP parses your polar_patch.toml
  2. scans files and folders you listed in ur toml
  3. uses libCST to extract the needed info about your plugins.
  4. creates a backup of the files to be modified
  5. creates a copy of the backup fresh each run
  6. applies the libCST transformer to add the attribute with type hint onto the corresponding Polars class
  7. adds the corresponding import for your plugin into polars in a type checking block

Added Attribute

Added Import

Notes

  • It is important to note that while this is minimally invasive, it is monkey patching the executing interpreters polars package.
  • libCST uses concrete syntax trees, thus the polars file is well preserved.

Beta Blockers

  • callable form of pl.api
  • inital functional hypothesis testing setup
  • basic logging
  • basic exception handling
  • unpin 3.12.4 to ^3.12

Stable Blockers

  • some maturity
  • The blessing of the polars team for the approach on issue

Features

  • automatic "hot reloading" since the type hint points directly to the implementation

In development

  • vsc extension for toml support via jsonschema

Roadmap

  • registering third party plugins in polar_patch.toml
  • plugin store

End Goal

An end-to-end framework for taking rust and/or python code into polars in python.

Status

This package is currently in alpha and ideas are welcome. Only classes registered with the @pl.api decorator are currently supported. Lack of support for the callable form of pl.api is seen as a blocker for a beta release. Also, many edge cases have not been addressed. This is another blocker for a beta release. There is bare minimum direct testing. Thorough testing is a blocker for a stable release. only python 3.12.4 is supported atm.

Installation

pip install polar-patch

Configuration

To specify paths to be scanned for plugins, create a polar_patch.toml file in your project root. (VSC IDE Support in Development)

[polar_patch]
scan_paths = ["path/to/your/plugin1.py", "path/to/your/polars/plugin/folder"]

Usage

To use the CLI tool provided by this package, run the following command:

pp mount

Undoing Changes

If you need to undo the changes made by this package, simply:

pp unmount

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polar_patch-0.0.6.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

polar_patch-0.0.6-py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page