ianlini / flatten-dict

A flexible utility for flattening and unflattening dict-like objects in Python.
MIT License
176 stars 36 forks source link

enumerate_types cannot handle numpy.ndarray #42

Closed pddees closed 3 years ago

pddees commented 3 years ago

The existence check of value immediately following the isinstance check against flattenable_types will throw a ValueError if used with a numpy ndarray.

import numpy as np
from flatten_dict import flatten
d = {'a': np.array([0, 1, 2]), 'b': 2}
dflat = flatten(d, enumerate_types=(np.ndarray,))

flatten_dict.py - Line 76 ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

ianlini commented 3 years ago

It seems that the if value: check is not necessary. I will try to remove it.