Returns a copy of d without empty leaves.

        https://stackoverflow.com/questions/27973988/python-how-to-remove-all-empty-fields-in-a-nested-dict/35263074
162866
def clean_empty(self, d=DEFAULT):
        
        if d is DEFAULT:
            d = self
        if isinstance(d, list):
            return [v for v in (self.clean_empty(v) for v in d) if v or v == 0]
        elif isinstance(d, type(self)):
            return type(self)({k: v for k, v in ((k, self.clean_empty(v)) for k, v in d.items()) if v or v == 0})
        elif isinstance(d, dict):
            return {k: v for k, v in ((k, self.clean_empty(v)) for k, v in d.items()) if v or v == 0}
        return d
1023508
def remove_properties_containing_None(properties_dict):
    
    # remove empty properties - as validations may fail
    new_dict  = dict()
    for key in properties_dict.keys():
        value = properties_dict[key]
        if value is not None:
            new_dict[key] = value
    return new_dict
237767
def copy(self):
        
        c = copy.copy(self)
        c._fieldDict = c._fieldDict.copy()
        return c
1071231
def __get_item_sh_fields_empty(self, rol, undefined=False):
        
        # If empty_field is None, the fields do not appear in index patterns
        empty_field = '' if not undefined else '-- UNDEFINED --'
        return {
            rol + "_id": empty_field,
            rol + "_uuid": empty_field,
            rol + "_name": empty_field,
            rol + "_user_name": empty_field,
            rol + "_domain": empty_field,
            rol + "_gender": empty_field,
            rol + "_gender_acc": None,
            rol + "_org_name": empty_field,
            rol + "_bot": False
        }
41519
def _get_non_empty_dict(cls, mapping):
        """"""
        res = {}
        for key, value in mapping.items():
            if hasattr(value, 'items'):
                value = cls._get_non_empty_dict(value)
            elif isinstance(value, list):
                value = cls._get_non_empty_list(value)
            if value not in [[], {}, None]:
                res[key] = value
        return res
1311833
def from_dict(cls, coll, d):
        
        return Mark(collection=coll, operation=Operation[d[cls.FLD_OP]],
                    pos=d[cls.FLD_MARK], field=d[cls.FLD_FLD])
651742
def leaves(self, nodes=None, unique=True):
        
        if nodes is None:
            return super(DependencyTree, self).leaves(unique=unique)

        res = list()
        for child_id in nodes:
            for sub_child in self._all_nodes[child_id].leaves(unique=unique):
                if not unique or sub_child not in res:
                    res.append(sub_child)
        return res
665990
def to_dict(self, omit=()):
        
        result = dict(self)
        for key in omit:
            if key in result:
                del result[key]
        return result
919107
def clean_dict_keys(d):
    
    new_d = {}
    for (k, v) in d.iteritems():
        new_d[str(k)] = v
    return new_d
197251
def _rel(self, copy=False):
        
        rel = {}
        for key, obj in vars(self).items():
            if not isinstance(obj, (pd.Series, pd.DataFrame, pd.SparseSeries, pd.SparseDataFrame)) and not key.startswith('_'):
                if copy and 'id' not in key:
                    rel[key] = deepcopy(obj)
                else:
                    rel[key] = obj
        return rel
178224
function() {
				var doc = this;
				var outDoc = doc.toObject(); // Rely on the toObject() syntax to strip out rubbish

				doc.getOIDs().forEach(function(node) {
					switch (node.fkType) {
						case 'objectId':
							var oidLeaf = _.get(doc, node.docPath);
							if (_.isUndefined(oidLeaf)) return; // Ignore undefined

							if (!o.utilities.isObjectID(oidLeaf)) {
								if (_.has(oidLeaf, '_id')) { // Already populated?
									_.set(outDoc, node.docPath, o.utilities.objectID(oidLeaf._id));
								} else { // Convert to an OID
									_.set(outDoc, node.docPath, o.utilities.objectID(oidLeaf));
								}
							}
							break;
						case 'objectIdArray':
							var oidLeaf = _.get(doc, node.schemaPath);
							_.set(outDoc, node.schemaPath, oidLeaf.map(function(leaf) {
								return o.utilities.isObjectID(leaf) ? leaf : o.utilities.objectID(leaf);
							}));
							break;
						default:
							return; // Ignore unsupported OID types
					}
				});

				return outDoc;
			}
338884
def omit_deep(omit_props, dct):
    

    omit_partial = omit_deep(omit_props)

    if isinstance(dict, dct):
        # Filter out keys and then recurse on each value that wasn't filtered out
        return map_dict(omit_partial, compact_dict(omit(omit_props, dct)))
    if isinstance((list, tuple), dct):
        # run omit_deep on each value
        return map(omit_partial, dct)
    # scalar
    return dct
153656
def _clean_xmldict_single_dic(self, dictionary):
        
        for k, v in dictionary.items():
            if v is None:
                dictionary[k] = ''
36474
def dict2str(self, d: Dict, joiner: str) -> str:
        
        result = str()
        for key in d:
            result = result + str(key) + " : "
            if isinstance(d[key], list):
                result = result + self.list2str(d[key], joiner) + joiner
            elif isinstance(d[key], dict):
                result = result + self.dict2str(d[key], joiner) + joiner
            elif d[key]:
                result = result + str(d[key]) + joiner
        return result
671492
def leaves(tree):
    
    lvs = []
    def _leaves(node):
        if np.isscalar(node):
            lvs.append(node)
        elif isinstance(node, tuple) and len(node) == 2:
            _leaves(node[0])
            _leaves(node[1])
        else:
            raise Exception("Not a tree!")

    _leaves(tree)
    return lvs
1219704
def dict(
        self, *, include: 'SetStr' = None, exclude: 'SetStr' = None, by_alias: bool = False, skip_defaults: bool = False
    ) -> 'DictStrAny':
        
        get_key = self._get_key_factory(by_alias)
        get_key = partial(get_key, self.fields)

        return_keys = self._calculate_keys(include=include, exclude=exclude, skip_defaults=skip_defaults)
        if return_keys is None:
            return {get_key(k): v for k, v in self._iter(by_alias=by_alias, skip_defaults=skip_defaults)}
        else:
            return {
                get_key(k): v for k, v in self._iter(by_alias=by_alias, skip_defaults=skip_defaults) if k in return_keys
            }
1329231
def from_dict(cls, d):
        
        return cls(xc=d.get("xc"), x=d.get("x"), c=d.get("c"))