Skip to content

Commit df5ae63

Browse files
jealousclaude
andauthored
Fix _tp() to always return pandas Series (#202)
When amount column is present, _tp() was returning a numpy array instead of a pandas Series, causing inconsistent behavior in downstream indicators like MFI. Now both code paths consistently return a Series via to_series(). Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5e3770c commit df5ae63

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![codecov](https://codecov.io/gh/jealous/stockstats/branch/master/graph/badge.svg?token=IFMD1pVJ7T)](https://codecov.io/gh/jealous/stockstats)
55
[![pypi](https://img.shields.io/pypi/v/stockstats.svg)](https://pypi.python.org/pypi/stockstats)
66

7-
VERSION: 0.6.6
7+
VERSION: 0.6.7
88

99
## Introduction
1010

stockstats.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -969,11 +969,13 @@ def _shifted_cr_sma(self, cr, window):
969969
cr_sma = self.sma(cr, window)
970970
return self.s_shift(cr_sma, -int(window / 2.5 + 1))
971971

972-
def _tp(self):
972+
def _tp(self) -> pd.Series:
973973
if "amount" in self:
974-
return self.amount.values / self.volume.values
975-
total = self.close.values + self.high.values + self.low.values
976-
return self.to_series(total / 3.0)
974+
tp = self.amount.values / self.volume.values
975+
else:
976+
total = self.close.values + self.high.values + self.low.values
977+
tp = total / 3.0
978+
return self.to_series(tp)
977979

978980
def _get_tp(self, meta: _Meta):
979981
self[meta.name] = self._tp()

test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@ def test_mfi(self):
728728
assert_that(mfi_15.loc[first], near_to(0.5))
729729
assert_that(mfi_15.loc[last], near_to(0.6733))
730730

731+
def test_mfi_with_amount(self):
732+
mfi = self._supor['mfi']
733+
assert_that(mfi.loc[20160817], near_to(0.48265))
734+
731735
def test_ker(self):
732736
stock = self.get_stock_90days()
733737
k = stock["ker"]

0 commit comments

Comments
 (0)