Implementation:TA Lib Ta lib python Abstract Input Preparation
| Knowledge Sources | |
|---|---|
| Domains | Data_Preparation, Technical_Analysis |
| Last Updated | 2026-02-09 22:00 GMT |
Overview
Concrete pattern for preparing OHLCV input data as dict, pandas DataFrame, or polars DataFrame for the Abstract API's set_input_arrays method.
Description
The Abstract API validates and stores input data via the set_input_arrays() method (or by assignment to the input_arrays property). It checks that all required price series keys exist in the provided data structure. The accepted types are defined in __INPUT_ARRAYS_TYPES which includes dict, pandas.DataFrame, and polars.DataFrame (when available).
Usage
Prepare a dict or DataFrame with OHLCV columns before passing to any Abstract API Function object.
Code Reference
Source Location
- Repository: ta-lib-python
- File: talib/_abstract.pxi
- Lines: L21-69 (__INPUT_PRICE_SERIES_DEFAULTS and input type detection)
Signature
# Input data preparation patterns
# Pattern 1: Dict of numpy arrays
inputs = {
'open': np.array([...], dtype=float),
'high': np.array([...], dtype=float),
'low': np.array([...], dtype=float),
'close': np.array([...], dtype=float),
'volume': np.array([...], dtype=float),
}
# Pattern 2: Pandas DataFrame
inputs = pd.DataFrame({
'open': [...], 'high': [...], 'low': [...],
'close': [...], 'volume': [...]
})
# Pattern 3: Polars DataFrame
inputs = pl.DataFrame({
'open': [...], 'high': [...], 'low': [...],
'close': [...], 'volume': [...]
})
Import
import numpy as np
from talib import abstract
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| input_arrays | dict / pd.DataFrame / pl.DataFrame | Yes | OHLCV data with named price series keys |
Outputs
| Name | Type | Description |
|---|---|---|
| validated_data | dict / pd.DataFrame / pl.DataFrame | Same structure, stored for indicator computation |
Usage Examples
Dict Input
import numpy as np
from talib import abstract
inputs = {
'open': np.random.random(100),
'high': np.random.random(100) + 1,
'low': np.random.random(100),
'close': np.random.random(100) + 0.5,
'volume': np.random.random(100) * 1000,
}
sma = abstract.Function('SMA')
sma.set_input_arrays(inputs)
DataFrame Input
import pandas as pd
from talib import abstract
df = pd.DataFrame({
'open': np.random.random(100),
'high': np.random.random(100) + 1,
'low': np.random.random(100),
'close': np.random.random(100) + 0.5,
'volume': np.random.random(100) * 1000,
})
sma = abstract.Function('SMA')
result = sma.run(df) # Returns pandas Series