Skip to content

Commit

Permalink
BUG: preserve index in _aligned_series
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Jevnik authored and llllllllll committed May 2, 2018
1 parent 05bf71d commit 0ba4d23
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion empyrical/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,32 @@ def excess_sharpe(returns, factor_returns, out=None):
roll_excess_sharpe = _create_binary_vectorized_roll_function(excess_sharpe)


def _to_pandas(ob):
"""Convert an array-like to a pandas object.
Parameters
----------
ob : array-like
The object to convert.
Returns
-------
pandas_structure : pd.Series or pd.DataFrame
The correct structure based on the dimensionality of the data.
"""
if isinstance(ob, (pd.Series, pd.DataFrame)):
return ob

if ob.ndim == 1:
return pd.Series(ob)
elif ob.ndim == 2:
return pd.DataFrame(ob)
else:
raise ValueError(
'cannot convert array of dim > 2 to a pandas structure',
)


def _aligned_series(*many_series):
"""
Return a new list of series containing the data in the input series, but
Expand Down Expand Up @@ -934,7 +960,7 @@ def _aligned_series(*many_series):
# dataframe has no ``itervalues``
return (
v
for _, v in iteritems(pd.concat(map(pd.Series, many_series), axis=1))
for _, v in iteritems(pd.concat(map(_to_pandas, many_series), axis=1))
)


Expand Down

0 comments on commit 0ba4d23

Please sign in to comment.