Utilities to log on dataframe pipelines
Project description
narlogs
Decorators for logging purposes for all your dataframes.
Install
uv pip install narlogs
Usage
The goal of this project is to make it simple to decorate your dataframe pipeline with some logs. There is a very nice decorator pattern for this and thanks to narwhals we can write utilities for these such that they work on a whole lot of dataframe libraries. The main use case for this is to log useful stats about the dataframe at each step of the pipeline.
import time
import polars as pl
import pandas as pd
from narlogs import print_step
# This is just some function for demo purposes, you can replace it with any function
@print_step
def identity(dataf, t=1):
time.sleep(t)
return dataf
# When we `.pipe` the function to the polars dataframe it starts printing
pl.read_csv("chickweight.csv").pipe(identity).pipe(identity, t=0.5)
# We get the exact same thing when we pipe it with a pandas dataframe, thanks to narwhals!
pd.read_csv("chickweight.csv").pipe(identity).pipe(identity, t=0.5)
This library also offers a general "callback" function if you want to be more flexible. Maybe you want to create an artifact of some sort or maybe you want to print a sample of the dataframe. Anything a Python function can do, it can do with this callback.
import time
import pandas as pd
import polars as pl
from narlogs import callback
@callback
def print_sample(dataf):
# You can use narwhals code inside here!
print(dataf.head(4))
@print_sample
def identity(dataf):
time.sleep(0.5)
return dataf
# You will now see a sample get printed, in both cases.
pl.read_csv("chickweight.csv").pipe(identity)
pd.read_csv("chickweight.csv").pipe(identity)
Try it live
To learn more, we recommend checking out this Marimo notebook. You can play with narlogs straight from the browser without having to download anything!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file narlogs-0.1.1.tar.gz.
File metadata
- Download URL: narlogs-0.1.1.tar.gz
- Upload date:
- Size: 6.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eea77774442a8f720d26354860f08f0532378d2c36bf8ad1ed6b2f1a208f4af1
|
|
| MD5 |
d7506c7c0064c831740bf8c9cdc50dce
|
|
| BLAKE2b-256 |
8e63d92340a1d25514cc4b81b982867795bf54dd65e8f83d010bfb433dc9654b
|
File details
Details for the file narlogs-0.1.1-py3-none-any.whl.
File metadata
- Download URL: narlogs-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac90048130faffd229c90c7381bc6a6ce0776bf20b0ec0bb44d9461355cb9916
|
|
| MD5 |
f7d3c9174c1ae5fa2ec44837fe2ba995
|
|
| BLAKE2b-256 |
774e75b45237c1428426af9dcde9dcea590b7efa9d4a13d9e7fbfd92df0be1d3
|