pydlm
pydlm copied to clipboard
Incorrect usage of `map` in Python 3
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.
This issue also arises when calling model.tune().
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!
I have also run into this from the PyPI version. Are you still intending to bring this up to date?
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 .