cvxportfolio icon indicating copy to clipboard operation
cvxportfolio copied to clipboard

values_in_time breaks with a null value for tau

Open thayes75 opened this issue 4 years ago • 1 comments

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

thayes75 avatar Apr 20 '20 15:04 thayes75

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.

altquant avatar Apr 29 '20 02:04 altquant