We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Original ticket http://projects.scipy.org/numpy/ticket/1591 on 2010-08-23 by trac user nasturtium86, assigned to unknown.
numpy.lib.io.flatten_dtype() raises "ValueError: too many values to unpack" when you run it on a dtype that has titles.
For example, this code works:
import numpy dtype1 = numpy.dtype([("Current","f8"),("Voltage","f8"), "Power","f8")]) print numpy.lib.io.flatten_dtype(dtype1)
But this code doesn't:
import numpy dtype2 = numpy.dtype([(("Amps","Current"),"f8"),(("Volts","Voltage"),"f8"),(("Watts","Power"),"f8")]) print numpy.lib.io.flatten_dtype(dtype2)
The following monkey patch fixes the problem:
def flatten_dtype(ndtype): """ Unpack a structured data-type. """ names = ndtype.names if names is None: return [ndtype] else: types = [] for field in names: typ_fields = ndtype.fields[field] flat_dt = flatten_dtype(typ_fields[0]) types.extend(flat_dt) return types numpy.lib.io.flatten_dtype=flatten_dtype
With this monkey patch in place, both dtype1 and dtype2 are handled correctly.
There is a thread open about this issue at [http://www.mail-archive.com/numpy-discussion@scipy.org/msg27441.html]
The text was updated successfully, but these errors were encountered:
@pierregm wrote on 2010-09-13
Sorry, something went wrong.
@rgommers wrote on 2010-10-14
>>> import numpy >>> dtype2 = numpy.dtype([(("Amps","Current"),"f8"),(("Volts","Voltage"),"f8"),(("Watts","Power"),"f8")]) >>> import numpy.lib.npyio >>> print(numpy.lib.npyio.flatten_dtype(dtype2)) [dtype('float64'), dtype('float64'), dtype('float64')]
Milestone changed to 1.6.0 by @mwiebe on 2011-05-24
1.6.0
No branches or pull requests
Original ticket http://projects.scipy.org/numpy/ticket/1591 on 2010-08-23 by trac user nasturtium86, assigned to unknown.
numpy.lib.io.flatten_dtype() raises "ValueError: too many values to unpack" when you run it on a dtype that has titles.
For example, this code works:
But this code doesn't:
The following monkey patch fixes the problem:
With this monkey patch in place, both dtype1 and dtype2 are handled correctly.
There is a thread open about this issue at [http://www.mail-archive.com/numpy-discussion@scipy.org/msg27441.html]
The text was updated successfully, but these errors were encountered: