Implementation:TA Lib Ta lib python Wrapper Price Data Input
| Knowledge Sources | |
|---|---|
| Domains | Data_Preparation, Technical_Analysis |
| Last Updated | 2026-02-09 22:00 GMT |
Overview
Concrete pattern for preparing price data as numpy float64 arrays, with transparent pandas/polars Series support via the _wrapper decorator.
Description
The _wrapper decorator in talib/__init__.py implements transparent type conversion for all TA-Lib indicator functions. When a pandas Series or polars Series is passed as input, the wrapper:
- Detects the input type (pandas, polars, or numpy)
- Converts to float64 numpy arrays
- Calls the underlying C function
- Converts output back to the original type (preserving pandas index)
This is a Pattern Doc — it documents the input data preparation pattern rather than a single API call.
Usage
Use this pattern when passing data to any TA-Lib indicator function. The wrapper is applied automatically to all 161 indicator functions and all streaming functions at module import time.
Code Reference
Source Location
- Repository: ta-lib-python
- File: talib/__init__.py
- Lines: L1-106 (pandas/polars detection and _wrapper decorator)
Signature
# Input preparation patterns (not a single function signature)
# Pattern 1: Direct numpy array
import numpy as np
close = np.array([1.0, 2.0, 3.0, 4.0, 5.0], dtype=float)
# Pattern 2: Pandas Series (auto-converted by _wrapper)
import pandas as pd
close = pd.Series([1.0, 2.0, 3.0, 4.0, 5.0], index=pd.date_range('2024-01-01', periods=5))
# Pattern 3: Polars Series (auto-converted by _wrapper)
import polars as pl
close = pl.Series([1.0, 2.0, 3.0, 4.0, 5.0])
Import
import numpy as np
import talib
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| price_data | np.ndarray / pd.Series / pl.Series | Yes | Price data (OHLCV components). Must be numeric (float64). |
| dtype | type | No | Must be float64. Integer arrays raise exceptions. |
Outputs
| Name | Type | Description |
|---|---|---|
| prepared_data | np.ndarray (float64) | Contiguous float64 array ready for C function consumption |
Usage Examples
NumPy Array Input
import numpy as np
import talib
# Create float64 price data
close = np.random.random(100)
# Pass directly to indicator function
sma = talib.SMA(close, timeperiod=20)
Pandas Series Input
import pandas as pd
import talib
# Create pandas Series with datetime index
dates = pd.date_range('2024-01-01', periods=100)
close = pd.Series(np.random.random(100), index=dates)
# _wrapper auto-converts and preserves index
sma = talib.SMA(close, timeperiod=20)
# sma is a pd.Series with the same index
Polars Series Input
import polars as pl
import talib
close = pl.Series("close", [1.0, 2.0, 3.0, 4.0, 5.0] * 20)
# _wrapper auto-converts to numpy, computes, converts back
sma = talib.SMA(close, timeperiod=5)
# sma is a pl.Series