You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your suspicion is justified to the extent that Quantity relies on np.array to do the coercion of lists, etc., to arrays, and np.array does not take iterators. The logic for np.array is that it is impossible to know the length of an iterator before iterating, so one is stuck anyway with first creating something like a list.
But perhaps we should deviate from that behaviour; it would mean changing the logic inside the isiterable(value) branch in Quantity.__new__. It still would be rather slow, though, and at least the example you point to is probably better done by pre-allocating an array and just filling it in a loop.
Today I spent some time in the astropy.timeseries.periodograms territory for hunting down the bug for #9236, and while now almost everything works I still have two failures that could easily be fixed if this line would work with Quantities (but of course np.fromiter doesn't work with object dtype):
https://github.com/astropy/astropy/blob/master/astropy/timeseries/periodograms/lombscargle/_statistics.py#L360
I'll do a workaround, but then wondered whether it's a valid use case to support Quantity initialization using iterators.
I suspect this will boil down to the same upstream issue as #5493.
The text was updated successfully, but these errors were encountered: