Skip to content

Commit

Permalink
BUG: Preserve columns in cum_returns.
Browse files Browse the repository at this point in the history
- Fixes a bug where we failed to maintain columns when calling
  `empyrical.cum_returns` on a DataFrame.
  • Loading branch information
Scott Sanderson committed Mar 12, 2018
1 parent 1c0978d commit 708ee2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion empyrical/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ def cum_returns(returns, starting_value=0, out=None):
if returns.ndim == 1 and isinstance(returns, pd.Series):
out = pd.Series(out, index=returns.index)
elif isinstance(returns, pd.DataFrame):
out = pd.DataFrame(out, index=returns.index)
out = pd.DataFrame(
out, index=returns.index, columns=returns.columns,
)

return out

Expand Down
4 changes: 4 additions & 0 deletions empyrical/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def assert_indexes_match(self, result, expected):
"""
assert_index_equal(result.index, expected.index)

if isinstance(result, pd.DataFrame) and \
isinstance(expected, pd.DataFrame):
assert_index_equal(result.columns, expected.columns)


class TestStats(BaseTestCase):

Expand Down

0 comments on commit 708ee2a

Please sign in to comment.