Lean icon indicating copy to clipboard operation
Lean copied to clipboard

PandasMapper Does Not Support Slice(None) in Loc Method

Open AlexCatarino opened this issue 3 years ago • 0 comments

Expected Behavior

Be able to use this pandas.DataFrame slicers.

Actual Behavior

PandasMapper throws KeyError exception:

raise KeyError(f"No key found for either mapped or original key. Mapped Key: {mKey}; Original Key: {oKey}")
  File "none", line 3, in Test

Potential Solution

N/A

Reproducing the Problem

Unit test:

        [TestCase("2013-10-07 04:00:00", true)]
        [TestCase("2013-10-07 04:00:00")]
        public void BackwardsCompatibilityDataFrame_loc_slice_none(string index, bool cache = false)
        {
            if (cache)
            {
                SymbolCache.Set("SPY", Symbols.SPY);
                SymbolCache.Set("AAPL", Symbols.AAPL);
            }

            using (Py.GIL())
            {
                dynamic test = PythonEngine.ModuleFromString("testModule",
                    $@"
def Test(dataFrame, symbols):
    data = dataFrame.loc[(slice(None), '{index}'), 'lastprice']").GetAttr("Test");

                var symbols = new List<Symbol> { Symbols.SPY, Symbols.AAPL };
                Assert.DoesNotThrow(() => test(GetTestDataFrame(symbols), symbols));
            }
        }

Notebook: slice_none

Checklist

  • [x] I have completely filled out this template
  • [x] I have confirmed that this issue exists on the current master branch
  • [x] I have confirmed that this is not a duplicate issue by searching issues
  • [x] I have provided detailed steps to reproduce the issue

AlexCatarino avatar Apr 23 '22 14:04 AlexCatarino