Skip to content

Commit 34daeeb

Browse files
authored
Merge pull request #225 from hyanwong/replace-namedtuple
Fix nested loop var and remove duplicate class name
2 parents d5128cb + 536a0a9 commit 34daeeb

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

tsdate/prior.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
from . import util
4040

4141

42-
PriorParams_base = namedtuple("PriorParams", "alpha, beta, mean, var")
43-
44-
45-
class PriorParams(PriorParams_base):
42+
class PriorParams(namedtuple("PriorParamsBase", "alpha, beta, mean, var")):
4643
@classmethod
4744
def field_index(cls, fieldname):
4845
return np.where([f == fieldname for f in cls._fields])[0][0]
@@ -652,24 +649,13 @@ def save_to_spans(prev_tree, node, num_fixed_at_0_treenodes):
652649
unary_descendants = set()
653650
for node in changed_nodes:
654651
children = prev_tree.children(node)
655-
if children is not None:
656-
if len(children) == 1:
657-
# Keep descending
658-
while True:
659-
children = prev_tree.children(node)
660-
if len(children) != 1:
661-
break
662-
unary_descendants.add(node)
663-
node = children[0]
664-
else:
665-
# Descend all branches, looking for unary nodes
666-
for node in prev_tree.children(node):
667-
while True:
668-
children = prev_tree.children(node)
669-
if len(children) != 1:
670-
break
671-
unary_descendants.add(node)
672-
node = children[0]
652+
for child in children:
653+
while True:
654+
children = prev_tree.children(child)
655+
if len(children) != 1:
656+
break
657+
unary_descendants.add(child)
658+
child = children[0]
673659

674660
# find all the nodes in the tree that might have changed their number
675661
# of descendants, and reset. This might include nodes that are not in

0 commit comments

Comments
 (0)