Skip to content

Commit cc91ebc

Browse files
committed
1.4.7
1 parent 9fda577 commit cc91ebc

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

docs/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ stock['hhv:5,open'].to_numpy()
274274

275275
### stock.cumulate() -> StockDataFrame
276276

277-
Cumulate the current data frame `stock` based on its time frame setting
277+
Cumulate the current data frame `stock` based on its time frame setting, and returns a new `StockDataFrame`
278278

279279
```py
280280
StockDataFrame(one_minute_kline_data_frame, time_frame='5m').cumulate()
@@ -286,7 +286,9 @@ see [Cumulation and DatetimeIndex][cumulation] for details
286286

287287
### stock.cum_append(other: DataFrame) -> StockDataFrame
288288

289-
Append `other` to the end of the current data frame `stock` and apply cumulation on them. And the following slice of code is equivalent to the above one:
289+
Append `other` to the end of the current data frame `stock`, apply cumulation on them, and return a new `StockDataFrame`
290+
291+
And the following slice of code is equivalent to the above one:
290292

291293
```py
292294
StockDataFrame(time_frame='5m').cum_append(one_minute_kline_data_frame)

stock_pandas/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
cumulators
2121
)
2222

23-
__version__ = '1.4.6'
23+
__version__ = '1.4.7'

stock_pandas/meta/cumulator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def cum_append(
254254
if not len(other):
255255
raise ValueError('the data frame to be appended is empty')
256256

257-
# current_unclosed = self._unclosed
257+
current_unclosed = self._unclosed
258258

259259
other = self._convert_to_date_df(other)
260260

@@ -318,7 +318,9 @@ def cum_append(
318318

319319
unclosed = self._unclosed
320320

321-
# self._unclosed = current_unclosed
321+
# .cum_append() will create a new data frame,
322+
# so we need to restore `self._unclosed`
323+
self._unclosed = current_unclosed
322324

323325
return new, unclosed, source
324326

test/test_cum_append.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def test_time_frames(tencent):
6565
time_frames = [
6666
('3m', -2),
6767
('5m', -5),
68+
('15m', -5),
6869
('1h', None),
6970
('1d', None),
7071
('1M', None),
@@ -74,11 +75,17 @@ def test_time_frames(tencent):
7475
for time_frame, test_start in time_frames:
7576
stock = tencent.copy()
7677

77-
cumulated = StockDataFrame(
78+
df = StockDataFrame(
7879
stock,
7980
date_col=TIME_KEY,
8081
time_frame=time_frame
81-
).cumulate()
82+
)
83+
84+
cumulated = df.cumulate()
85+
86+
assert cumulated.equals(cumulated.cumulate()), 'should be value identical'
87+
88+
assert cumulated is not df, '.cumulate() should return a new object'
8289

8390
to_compare = stock if test_start is None else stock.iloc[test_start:]
8491

@@ -96,6 +103,9 @@ def test_cum_append_from_empty(tencent):
96103

97104
for i in range(LENGTH):
98105
stock_new = stock.cum_append(tencent.iloc[i:i + 1])
106+
assert stock_new.equals(stock.cum_append(tencent.iloc[i:i + 1]))
107+
assert not stock_new.equals(stock)
108+
99109
assert isinstance(stock, StockDataFrame)
100110

101111
expect_cumulated(tencent, stock, i)

0 commit comments

Comments
 (0)