pydlm icon indicating copy to clipboard operation
pydlm copied to clipboard

Incorrect usage of `map` in Python 3

Open bdewilde opened this issue 8 years ago • 4 comments

I'm trying to plot individual components of a fit model using model.plot(component_name), and am getting a TypeError that arises from incorrect usage of map in Python 3. In Python 2, map produces a list that you can index into, but that is not the case in Python 3. Here's the full traceback:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-9e7922b7c508> in <module>()
----> 1 model.plot('linear_trend')

~/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pydlm/dlm.py in plot(self, name)
   1035                                   data=data,
   1036                                   result=self.result,
-> 1037                                   options=self.options)
   1038         dlmPlot.plotout()
   1039 

~/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pydlm/plot/dlmPlot.py in plotComponent(time, data, result, options)
    352             upper, lower = getInterval(data['filteredMean'],
    353                                        map(abs, data['filteredVar']),
--> 354                                        p=options.confidence)
    355 
    356             plotInterval(time=time[start:end],

~/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pydlm/base/tools.py in getInterval(means, var, p)
     73     lower = [0] * len(means)
     74     for i in range(0, len(means)):
---> 75         upper[i] = means[i] + alpha * math.sqrt(var[i])
     76         lower[i] = means[i] - alpha * math.sqrt(var[i])
     77 

TypeError: 'map' object is not subscriptable

And here's a minimal code example to clarify what's going wrong:

>>> map(abs, [-1,2,-3,4])[0]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-22af85735bae> in <module>()
----> 1 map(abs, [-1,2,-3,4])[0]

TypeError: 'map' object is not subscriptable

Wrapping those arguments in list() calls would probably fix it, but maybe there's a better way.

bdewilde avatar Aug 31 '17 17:08 bdewilde

This issue also arises when calling model.tune().

bdewilde avatar Aug 31 '17 19:08 bdewilde

Hi bdewilde,

Thanks for pointing out! Apologize for my late reply (being busy with other stuffs past weeks). The error has been fixed in the github version. I will soon release one along with some other changes.

Thanks again!

wwrechard avatar Sep 22 '17 09:09 wwrechard

I have also run into this from the PyPI version. Are you still intending to bring this up to date?

RJTK avatar Feb 10 '18 16:02 RJTK

Sure, sorry I was extremely busy recently. I will do a release today. Thanks! On Sat, Feb 10, 2018 at 8:47 AM Ryan Kinnear [email protected] wrote:

I have also run into this from the PyPI version. Are you still intending to bring this up to date?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/wwrechard/pydlm/issues/16#issuecomment-364670566, or mute the thread https://github.com/notifications/unsubscribe-auth/AIDNcgNvzPJsiXBInpxLejaJsX5xYueaks5tTcgtgaJpZM4PJJGS .

wwrechard avatar Feb 10 '18 20:02 wwrechard