PyTimeTK 
Time series easier, faster, more fun. Pytimetk.
Please β us on GitHub (it takes 2-seconds and means a lot).
1 Introducing pytimetk: Simplifying Time Series Analysis for Everyone
Time series analysis is fundamental in many fields, from business forecasting to scientific research. While the Python ecosystem offers tools like pandas
, they sometimes can be verbose and not optimized for all operations, especially for complex time-based aggregations and visualizations.
Enter pytimetk. Crafted with a blend of ease-of-use and computational efficiency, pytimetk
significantly simplifies the process of time series manipulation and visualization. By leveraging the polars
backend, you can experience speed improvements ranging from 3X to a whopping 3500X. Letβs dive into a comparative analysis.
Features/Properties | pytimetk | pandas (+matplotlib) |
---|---|---|
Speed | π 3X to 3500X Faster | π’ Standard |
Code Simplicity | π Concise, readable syntax | π Often verbose |
plot_timeseries() |
π¨ 2 lines, no customization | π¨ 16 lines, customization needed |
summarize_by_time() |
π 2 lines, 13.4X faster | π 6 lines, 2 for-loops |
pad_by_time() |
β³ 2 lines, fills gaps in timeseries | β No equivalent |
anomalize() |
π 2 lines, detects and corrects anomalies | β No equivalent |
augment_timeseries_signature() |
π 1 line, all calendar features | π 29 lines of dt extractors |
augment_rolling() |
ποΈ 10X to 3500X faster | π’ Slow Rolling Operations |
polars .tk plotting |
β
Plot directly on pl.DataFrame (plot_timeseries , plot_anomalies , plot_correlation_funnel , β¦) |
β pandas-only accessor |
polars .tk accessor |
β
Core, feature, and plotting helpers available via .tk on pandas/polars |
β N/A |
Feature store & caching (beta) | ποΈ Persist, version, and reuse feature sets (with optional MLflow logging) | β Manual recompute, no metadata lineage |
GPU acceleration (beta) | β‘ Optional RAPIDS-powered pipelines with automatic CPU fallback | β CPU only |
As evident from the table, pytimetk is not just about speed; it also simplifies your codebase. For example, summarize_by_time()
, converts a 6-line, double for-loop routine in pandas
into a concise 2-line operation. And with the polars
engine, get results 13.4X faster than pandas
!
Similarly, plot_timeseries()
dramatically streamlines the plotting process, encapsulating what would typically require 16 lines of matplotlib
code into a mere 2-line command in pytimetk, without sacrificing customization or quality. And with plotly
and plotnine
engines, you can create interactive plots and beautiful static visualizations with just a few lines of code.
For calendar features, pytimetk offers augment_timeseries_signature()
which cuts down on over 30 lines of pandas
dt extractions. For rolling features, pytimetk offers augment_rolling()
, which is 10X to 3500X faster than pandas
. It also offers pad_by_time()
to fill gaps in your time series data, and anomalize()
to detect and correct anomalies in your time series data.
Join the revolution in time series analysis. Reduce your code complexity, increase your productivity, and harness the speed that pytimetk brings to your workflows.
Explore more at our pytimetk homepage.
2 Installation
Install the latest stable version of pytimetk
using pip
:
pip install pytimetk
Alternatively you can install the development version:
pip install --upgrade --force-reinstall git+https://github.com/business-science/pytimetk.git
3 Quickstart:
This is a simple code to test the function summarize_by_time
:
import pytimetk as tk
import pandas as pd
= tk.datasets.load_dataset('bike_sales_sample')
df 'order_date'] = pd.to_datetime(df['order_date'])
df[
\
df "category_2") \
.groupby(
.summarize_by_time(='order_date',
date_column= 'total_price',
value_column= "MS",
freq = ['mean', 'sum'],
agg_func = "polars"
engine )
3.1 Whatβs New in pytimetk 2.1.0
- GPU acceleration (Beta) unlocks optional NVIDIA RAPIDS support for feature engineering (lags, diffs, leads, rolling/expanding statistics, finance indicators, etc.) and Polars lazy pipelines with automatic CPU fallback.
- Works with
polars.LazyFrame.collect(engine="gpu")
; setPYTIMETK_POLARS_GPU=0
if you need to force CPU execution. pytimetk.utils.gpu_support
exposes helpers such asis_cudf_available()
andis_polars_gpu_available()
so you can assert runtime readiness.- CPU-only environments run unchanged because GPU acceleration remains fully opt-in.
Enable GPU support
pip install pytimetk[gpu] --extra-index-url=https://pypi.nvidia.com
pip install "polars[gpu]" --extra-index-url=https://pypi.nvidia.com
See the GPU acceleration guide for environment validation commands, supported APIs, and current limitations.
3.2 Whatβs New in pytimetk 2.0.0
- Added polars
.tk
accessor support for plotting helpers (plot_timeseries
,plot_anomalies
,plot_anomalies_decomp
,plot_anomalies_cleaned
,plot_correlation_funnel
). - Polars users can now call these functions directly on
pl.DataFrame
objects via the.tk
accessor; results mirror the pandas interface (PlotlyFigure
or plotnineggplot
). - See the change log for more details.
3.3 Feature Store & Caching (Beta)
The Feature Store is currently released as a Beta capability. APIs, configuration options, and storage formats may change in upcoming releases. Please share feedback or issues so we can stabilize it quickly.
Persist expensive feature engineering steps once and reuse them everywhere. Register a transform, build it on a dataset, and reload it in any notebook or job with automatic versioning, metadata, and cache hits.
import pandas as pd
import pytimetk as tk
= tk.load_dataset("bike_sales_sample", parse_dates=["order_date"])
df
= tk.FeatureStore()
store
store.register("sales_signature",
lambda data: tk.augment_timeseries_signature(
data,="order_date",
date_column="pandas",
engine
),=("order_id",),
default_key_columns="Calendar signatures for sales orders.",
description
)
= store.build("sales_signature", df)
result print(result.from_cache) # False first run, True on subsequent builds
- Supports local disk or any
pyarrow
filesystem (e.g.,s3://
,gs://
) via theartifact_uri
parameter, plus optional file-based locking for concurrent jobs. - Optional MLflow helpers capture feature versions and artifacts with your experiments for reproducible pipelines.
4 Documentation
Get started with the pytimetk documentation
5 π More Coming Soonβ¦
We are in the early stages of development. But itβs obvious the potential for pytimetk
now in Python. π
- Please β us on GitHub (it takes 2-seconds and means a lot).
- To make requests, please see our Project Roadmap GH Issue #2. You can make requests there.
- Want to contribute? See our contributing guide here.
6 βοΈ Star History
Please β us on GitHub (it takes 2 seconds and means a lot).