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
{{ message }}
Repository navigation
Concatenate with sequence that contains empty sequences. (Trac #988) #1586
I have a lot of old-style Numeric stuff that likes to concatenate lists
of indices which then were used with take [which does not like floats]. So
below [in theory] I attach my attempt at a patch so that empty items in the sequence are
not used to influence the common type that is used by PyArray_ConvertToCommonType.
Maybe it is of some value, or maybe I didn't do this in a kosher manner and
someone else has an idea of where things should be rethought for this defect?
The patch is not a unified diff and can't be viewed on trac. It is also against an outdated version. It needs a closer look at the original function to see if it is good.
Apart from that, I think the current behavior should be fixed, but maybe this isn't the best fix. It needs some thought.
The best way to avoid this kind of problem is to work with arrays rather than lists where possible, and specify explicit dtypes in the few times when you need to convert.
Activity
thouis commentedon Oct 19, 2012
Attachment added by trac user kelson on 2009-01-22: numpy121b.patch
thouis commentedon Oct 19, 2012
@charris wrote on 2009-04-11
The patch is not a unified diff and can't be viewed on trac. It is also against an outdated version. It needs a closer look at the original function to see if it is good.
Apart from that, I think the current behavior should be fixed, but maybe this isn't the best fix. It needs some thought.
thouis commentedon Oct 19, 2012
@charris wrote on 2009-04-11
It's a context diff and only one of the four chunks apply.
thouis commentedon Oct 19, 2012
@mwiebe wrote on 2011-03-24
This behavior is still in 1.6 beta.
thouis commentedon Oct 19, 2012
Milestone changed to
Unscheduledby @mwiebe on 2011-03-24charris commentedon Feb 18, 2014
Still here in 1.9-devel
BUG, MANT: concatenate of empty sequences, fixes numpy#1586
BUG, MANT: concatenate of empty sequences, fixes numpy#1586
eric-wieser commentedon Apr 7, 2017
On master,
concatenate ( [[1],[2],[3],[]] ).dtypechanged fromint32, tofloat64WGautier commentedon Sep 12, 2018
Still seeing this on 1.15.1.
eric-wieser commentedon Sep 12, 2018
In my opinion, returning float64 is correct, because
np.array([]).dtype = float64WGautier commentedon Sep 12, 2018
Technically true, but it's not the most intuitive result from a simple concatenate function.
I will work around it, thanks for the quick answer.
eric-wieser commentedon Sep 13, 2018
The best way to avoid this kind of problem is to work with arrays rather than lists where possible, and specify explicit dtypes in the few times when you need to convert.
mattip commentedon Apr 30, 2019
Closing