docs: def unnest_child_dict(parent, key, parent_name=''):
      """
      If ``parent`` dictionary has a ``key`` whose ``val`` is a dict,
      unnest ``val``'s fields into ``parent`` and remove ``key``.
  
      >>> parent = {'province': 'Québec', 'capital': {'name': 'Québec City', 'pop': 491140}}
      >>> unnest_child_dict(parent, 'capital', 'provinces')
      >>> pprint(parent)
      {'capital_name': 'Québec City', 'capital_pop': 491140, 'province': 'Québec'}
  
      >>> parent = {'province': 'Québec', 'capital': {'id': 1, 'name': 'Québec City', 'pop': 491140}}
      >>> unnest_child_dict(parent, 'capital', 'provinces')
      >>> pprint(parent)
      {'capital_id': 1,
       'capital_name': 'Québec City',
       'capital_pop': 491140,
       'province': 'Québec'}
  
      >>> parent = {'province': 'Québec', 'capital': {'id': 1, 'name': 'Québec City'}}
      >>> unnest_child_dict(parent, 'capital', 'provinces')
      >>> pprint(parent)
      {'capital': 'Québec City', 'province': 'Québec'}
  
      """
      val = parent[key]
      name = "%s['%s']" % (parent_name, key)
      logging.debug("Unnesting dict %s" % name)
      id = _id_fieldname(val, parent_name)
      if id:
          logging.debug("%s is %s's ID" % (id, key))
          if len(val) <= 2:
              logging.debug('Removing ID column %s.%s' % (key, id))
              val.pop(id)
      if len(val) == 0:
          logging.debug('%s is empty, removing from %s' % (name, parent_name))
          parent.pop(key)
          return
      elif len(val) == 1:
          logging.debug('Nested one-item dict in %s, making scalar.' % name)
          parent[key] = list(val.values())[0]
          return
      else:
          logging.debug('Pushing all fields from %s up to %s' % (name, parent_name))
          new_field_names = ['%s_%s' % (key, child_key.strip('_')) for child_key in val]
          overlap = (set(new_field_names) & set(parent)) - set(id or [])
          if overlap:
              logging.error("Could not unnest child %s; %s present in %s"
                            % (name, key, ','.join(overlap), parent_name))
              return
          for (child_key, child_val) in val.items():
              new_field_name = '%s_%s' % (key, child_key.strip('_'))
              parent[new_field_name] = child_val
          parent.pop(key)