Skip to content

Commit 708ee2a

Browse files
author
Scott Sanderson
committed
BUG: Preserve columns in cum_returns.
- Fixes a bug where we failed to maintain columns when calling `empyrical.cum_returns` on a DataFrame.
1 parent 1c0978d commit 708ee2a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

empyrical/stats.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ def cum_returns(returns, starting_value=0, out=None):
237237
if returns.ndim == 1 and isinstance(returns, pd.Series):
238238
out = pd.Series(out, index=returns.index)
239239
elif isinstance(returns, pd.DataFrame):
240-
out = pd.DataFrame(out, index=returns.index)
240+
out = pd.DataFrame(
241+
out, index=returns.index, columns=returns.columns,
242+
)
241243

242244
return out
243245

empyrical/tests/test_stats.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def assert_indexes_match(self, result, expected):
3636
"""
3737
assert_index_equal(result.index, expected.index)
3838

39+
if isinstance(result, pd.DataFrame) and \
40+
isinstance(expected, pd.DataFrame):
41+
assert_index_equal(result.columns, expected.columns)
42+
3943

4044
class TestStats(BaseTestCase):
4145

0 commit comments

Comments
 (0)