Skip to content

Concatenate with sequence that contains empty sequences. (Trac #988) #1586

Closed

Description

@thouis

Original ticket http://projects.scipy.org/numpy/ticket/988 on 2009-01-22 by trac user kelson, assigned to unknown.

Howdy,

After searching for this defect, perhaps nobody else has been bothered
by this behaviour, but has anybody else noticed:

concatenate ( [[1],[2],[3],[4]] ).dtype = int32

concatenate ( [[1],[2],[3],[]] ).dtype = int32

concatenate ( [[],[2],[3],[4]] ).dtype = float64

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?

Cheerio.

Activity

  1. thouis commented on Oct 19, 2012

    @thouis
    ContributorAuthor

    Attachment added by trac user kelson on 2009-01-22: numpy121b.patch

  2. thouis commented on Oct 19, 2012

    @thouis
    ContributorAuthor

    @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.

  3. thouis commented on Oct 19, 2012

    @thouis
    ContributorAuthor

    @charris wrote on 2009-04-11

    It's a context diff and only one of the four chunks apply.

  4. thouis commented on Oct 19, 2012

    @thouis
    ContributorAuthor

    @mwiebe wrote on 2011-03-24

    This behavior is still in 1.6 beta.

  5. thouis commented on Oct 19, 2012

    @thouis
    ContributorAuthor

    Milestone changed to Unscheduled by @mwiebe on 2011-03-24

  6. charris commented on Feb 18, 2014

    @charris
    Member

    Still here in 1.9-devel

    In [89]: concatenate ( [[1],[2],[3],[4]] ).dtype
    Out[89]: dtype('int64')
    
    In [90]: concatenate ( [[1],[2],[3],[]] ).dtype
    Out[90]: dtype('float64')
    
  7. added 2 commits that reference this issue on Mar 22, 2016
    943e6cf
  8. added a commit that references this issue on Apr 3, 2017
    3b9f052
  9. eric-wieser commented on Apr 7, 2017

    @eric-wieser
    Member

    On master, concatenate ( [[1],[2],[3],[]] ).dtype changed from int32, to float64

  10. WGautier commented on Sep 12, 2018

    @WGautier

    Still seeing this on 1.15.1.

    >>> np.version.version
    '1.15.1'
    >>> np.concatenate(([],[1])).dtype
    dtype('float64')
    >>> np.concatenate(([2],[1])).dtype
    dtype('int64')
    
  11. eric-wieser commented on Sep 12, 2018

    @eric-wieser
    Member

    In my opinion, returning float64 is correct, because np.array([]).dtype = float64

  12. WGautier commented on Sep 12, 2018

    @WGautier

    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.

  13. eric-wieser commented on Sep 13, 2018

    @eric-wieser
    Member

    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.

  14. mattip commented on Apr 30, 2019

    @mattip
    Member

    Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions