-
Notifications
You must be signed in to change notification settings - Fork 40
Error when an item in pykov.Chain is None #21
Copy link
Copy link
Open
Description
Hey,
first of all this is my first time using github and also i'm very new to python so be gentle with me..
I have a pykov.Chain where one of the items is None and when i'm trying to use the function chain.move(None) i get the following error:
AttributeError: 'OrderedDict' object has no attribute 'choose'
to fix it i did the following changes in the succ function (i only use positive numbers in my project):
from:
def succ(self, key=None):
try:
if key is not None:
return self._succ[key]
else:
return self._succ
except AttributeError:
self._succ = OrderedDict([(state, Vector()) for state in self.states()])
for link, probability in six.iteritems(self):
self._succ[link[0]][link[1]] = probability
if key is not None:
return self._succ[key]
else:
return self._succ
to:
def succ(self, key=-1):
try:
if key is not -1:
return self._succ[key]
else:
return self._succ
except AttributeError:
self._succ = OrderedDict([(state, Vector()) for state in self.states()])
for link, probability in six.iteritems(self):
self._succ[link[0]][link[1]] = probability
if key is not -1:
return self._succ[key]
else:
return self._succ
My solution works for me, but is there a better way?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels