@@ -564,18 +564,20 @@ def _update_paths(
564564
565565 FIXME: ROOT in mass-update_paths NOT IMPLEMENTED
566566 """
567- ret_doc = None # Collect here any changed dataframe, ro return.
568- # The `group` is a list of paths with common prefix (root)
569- # currently being built. `group_prefix` is the 1st step.
570- group_prefix = None
567+ ret_doc = None # Collect here any changed dataframe, to return.
568+ # A `group` is a list of paths with common prefix (root)
569+ # currently being built.
570+ # The `last_prefix` & `next_prefix` detect when group's 1st step
571+ # has changed (proceeded to the next `group)`.
571572 group : List [Tuple [str , Any ]] = () # Begin with a blocker value.
573+ last_prefix = None
572574 for i , (path , value ) in enumerate ((* paths_vals , ((UNSET ,), UNSET ))):
573575 assert len (path ) >= 1 or value is UNSET , locals ()
574576
575577 next_prefix = path [0 ]
576- if next_prefix != group_prefix :
578+ if next_prefix != last_prefix :
577579 if len (path ) == 1 and value is not UNSET :
578- # Assign value and proceed to the next one ,
580+ # Assign "tip" value before proceeding to the next group ,
579581 # THOUGH if a deeper path with this same prefix follows,
580582 # it will overwrite the value just written.
581583 new_doc = set_or_concatenate_dataframe (
@@ -584,19 +586,19 @@ def _update_paths(
584586 if new_doc is not None :
585587 doc = ret_doc = new_doc
586588 else :
587- if group_prefix : # Is it past the 1st loop?
588- ## Recurse into sub-group.
589- #
589+ if last_prefix : # Is it past the 1st loop?
590590 child = None
591- if group_prefix in doc :
592- child = doc [group_prefix ]
591+ if last_prefix in doc :
592+ child = doc [last_prefix ]
593593 if not is_collection (child ):
594- _log_overwrite (group_prefix , doc , child )
594+ _log_overwrite (last_prefix , doc , child )
595595 child = None
596596
597597 if child is None :
598- child = doc [group_prefix ] = container_factory ()
598+ child = doc [last_prefix ] = container_factory ()
599599
600+ ## Recurse into sub-group.
601+ #
600602 new_child = _update_paths (
601603 child ,
602604 [(path [1 :], value ) for path , value in group ],
@@ -606,12 +608,10 @@ def _update_paths(
606608 concat_axis ,
607609 )
608610 if new_child is not None :
609- doc [group_prefix ] = new_child
611+ doc [last_prefix ] = new_child
610612
611- group_prefix , group = (
612- next_prefix ,
613- [(path , value )],
614- ) # prepare the next group
613+ # prepare the next group
614+ last_prefix , group = (next_prefix , [(path , value )])
615615 else :
616616 assert len (path ) > 1 , locals () # shortest path switches group.
617617 group .append ((path , value )) # pylint: disable=no-member
0 commit comments