Skip to content

Commit 2453737

Browse files
committed
fix: accept DataFrame inputs in abstract Function.run
Signed-off-by: Tianlang (Jackie) Chen <305351710+jackiectl2@users.noreply.github.com>
1 parent c9f01aa commit 2453737

3 files changed

Lines changed: 32 additions & 17 deletions

File tree

‎talib/_abstract.pxi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class Function(object):
408408
This is a shortcut to the outputs property that also allows setting
409409
the input_arrays dict.
410410
"""
411-
if input_arrays:
411+
if input_arrays is not None:
412412
self.set_input_arrays(input_arrays)
413413
self.__call_function()
414414
return self.outputs

‎talib/_ta_lib.c‎

Lines changed: 16 additions & 16 deletions
Large diffs are not rendered by default.

‎tests/test_abstract.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,18 @@ def worker(i):
444444

445445
with ThreadPoolExecutor(4) as pool:
446446
list(pool.map(worker, range(4)))
447+
448+
449+
@pytest.mark.parametrize("frame_type", ["pandas", "polars"])
450+
@pytest.mark.parametrize("empty", [False, True])
451+
def test_run_with_dataframe(frame_type, empty):
452+
module = pytest.importorskip(frame_type)
453+
values = np.array([] if empty else [2.0, 4.0, 6.0, 8.0])
454+
frame = module.DataFrame({"close": values})
455+
indicator = abstract.Function('SMA', timeperiod=2)
456+
result = indicator.run(frame)
457+
assert isinstance(result, module.Series)
458+
assert_array_equal(result.to_numpy(), talib.SMA(values, timeperiod=2))
459+
if frame_type == 'pandas':
460+
assert result.index.equals(frame.index)
461+
assert_array_equal(indicator.run().to_numpy(), result.to_numpy())

0 commit comments

Comments
 (0)