cvxportfolio
cvxportfolio copied to clipboard
values_in_time breaks with a null value for tau
Not sure what is happening but I had to modify my values_in_time code to looks like the following to address the slicing with a null tau value (note the added "mi_slice" bit). Is anyone else noticing this?
if hasattr(obj, '__call__'):
return obj(t, tau)
if isinstance(obj, pd.Series) or isinstance(obj, pd.DataFrame):
try:
if isinstance(obj.index, pd.MultiIndex):
mi_slice = (t, tau)
if (tau is None) or pd.isnull(tau):
mi_slice = (t, )
return obj.loc[mi_slice]
else:
return obj.loc[t]
except KeyError:
return obj
return obj
I can corroborate your issue. values_in_time doesn't work for multiindices w/no tau. (I'm using Pandas 1.0). Your solution works (though tau is None
is redundant), as does df.xs(t, level=0)
. I suggest you open a PR.