Expands a dictionary into a list of immutables with cartesian product

    :param d: dictionary (of strings or lists)
    :returns: cartesian product of list parts
437784
def expand_dict_as_keys(d):
    
    to_product = []
    for key, values in sorted(d.items()):
        # if we sort the inputs here, itertools.product will keep a stable sort order for us later
        key_values = sorted([(key, v) for v in utils.ensure_listable(values) if v is not None])
        if key_values:
            to_product.append(key_values)
    return list(itertools.product(*to_product))
934137
def merge_dicts(d1, d2):
    
    for k in set(d1.keys()).union(d2.keys()):
        if k in d1 and k in d2:
            if isinstance(d1[k], dict) and isinstance(d2[k], dict):
                yield (k, dict(merge_dicts(d1[k], d2[k])))
            elif isinstance(d1[k], list):
                if isinstance(d2[k], list):
                    d1[k].extend(d2[k])
                else:
                    d1[k].append(d2[k])
                yield(k, d1)
            else:
                # If one of the values is not a dict, you can't continue merging it.
                # Value from second dict overrides one in first and we move on.
                yield (k, d2[k])
                # Alternatively, replace this with exception raiser to alert you of value conflicts
        elif k in d1:
            yield (k, d1[k])
        else:
            yield (k, d2[k])
441576
def expanding(self, *args, **kwargs):
        
        from pandas.core.window import ExpandingGroupby
        return ExpandingGroupby(self, *args, **kwargs)
137181
def update(self, a, b, c, d):
        
        self.table.ravel()[:] = [a, b, c, d]
        self.N = self.table.sum()
694729
def convert_to_str(d):
    
    d2 = {}
    for k, v in d.items():
        k = str(k)
        if type(v) in [list, tuple]:
            d2[k] = [str(a) for a in v]
        elif type(v) is dict:
            d2[k] = convert_to_str(v)
        else:
            d2[k] = str(v)
    return d2
160486
def from_dict(cls, d):
        
        assert isinstance(d, dict)
        init_args = dict()
        for key, is_required in cls.dictionary_attributes.iteritems():
            try:
                init_args[key] = d[key]
            except KeyError:
                if is_required:
                    raise DictConvertible.Error('missing key in dictionary', cls, missing_key=key)
        return cls(**init_args)
734833
def nested_set_dict(d, keys, value):
    
    assert keys
    key = keys[0]
    if len(keys) == 1:
        if key in d:
            raise ValueError("duplicated key '{}'".format(key))
        d[key] = value
        return
    d = d.setdefault(key, {})
    nested_set_dict(d, keys[1:], value)
388428
def from_dict(cls, d):
        
        s = Structure.from_dict(d['structure'])
        return cls(s, d['graphs'])
422499
def DictKeyColumns(d):
    ''
    return [ColumnItem(k, k, type=deduceType(d[k])) for k in d.keys()]
806911
def recursively_update(d, d2):
  """"""
  for k, v in d2.items():
    if k in d:
      if isinstance(v, dict):
        recursively_update(d[k], v)
        continue
    d[k] = v
821059
def clean_dict(d):
    
    ktd = list()
    for k, v in d.items():
        if not v:
            ktd.append(k)
        elif type(v) is dict:
            d[k] = clean_dict(v)
    for k in ktd:
        d.pop(k)
    return d
530789
def update(self, d):
        
        for (k, v) in d.items():
            if k not in self or self[k] != v:
                self[k] = v
949117
def flatten_dict(d,
                 parent_key='', sep='.',
                 ignore_under_prefixed=True,
                 mark_value=True):
    '''
    
    '''
    items = {}
    for k in d:
        if ignore_under_prefixed and k.startswith('__'): continue
        v = d[k]
        if mark_value and k.startswith('_') and not k.startswith('__'):
            v = MarkValue(repr(v))

        new_key = sep.join((parent_key, k)) if parent_key else k
        if isinstance(v, collections.MutableMapping):
            items.update(flatten_dict(v, new_key, sep=sep,
                                        ignore_under_prefixed=True,
                                        mark_value=True)
                            )
        else:
            items[new_key] = v

    return items
840801
def invertDictMapping(d):
    
    inv_map = {}
    for k, v in d.items():
        inv_map[v] = inv_map.get(v, [])
        inv_map[v].append(k)
    return inv_map
1314707
def _str2array(d):
    
    if type(d) == list:
        return np.asarray([_str2array(s) for s in d])
    ins = StringIO(d)
    return np.loadtxt(ins)
1357528
def _expand_one_key_dictionary(_dict):
    '''
    
    '''
    key = next(six.iterkeys(_dict))
    value = _dict[key]
    return key, value
64506
def _rapply(d, func, *args, **kwargs):
    """"""
    if isinstance(d, (tuple, list)):
        return [_rapply(each, func, *args, **kwargs) for each in d]
    if isinstance(d, dict):
        return {
            key: _rapply(value, func, *args, **kwargs) for key, value in iteritems(d)
        }
    else:
        return func(d, *args, **kwargs)