Skip to content

object array construction should require explicitly specifying dtype=object #5353

Open

Description

@argriffing

This possibility was raised by #5303 (comment) so I'm moving this topic to its own github issue. Problems like scipy/scipy#4239 among others could be softened by making this change although it could bring backwards compatibility issues.

Activity

  1. argriffing commented on Dec 27, 2014

    @argriffing
    ContributorAuthor
  2. mhvk commented on May 25, 2015

    @mhvk
    Contributor

    An intermediate solution, which I suggested in #5844, is an explicit opt-out mechanism, perhaps using __array__ = None. It has the advantage of being backwards compatible, and should have the result that ndarray binops return NotImplemented.

  3. argriffing commented on Jul 16, 2015

    @argriffing
    ContributorAuthor

    +1's from notes linked from a mailing list post:

    object array coercion : everyone here agrees that actually making these things (= all the times asarray returns an object array when the input is not an object array and when dtype=object was not given explicitly) an error would be a good idea

  4. ahaldane commented on Jul 18, 2015

    @ahaldane
    Member

    A while ago I wrote up some "documentation" of how object arrays might work ideally, which includes various special cases and this explicit dtype=object change. If it's of any interest to anyone I put it up here.

  5. mhvk commented on Jul 18, 2015

    @mhvk
    Contributor

    @ahaldane - thanks, at least for me that was very useful!

  6. njsmith commented on Jul 18, 2015

    @njsmith
    Member

    @ahaldane: any interest into evolving that into a NEP? (Like a PEP but for
    numpy -- would need to be a bit clearer about what was new changes versus
    current behavior and what kind of strategy would be used in getting from
    here to there, then go to the mailing list for discussion. But that would
    be the route to making it closer to reality :-))
    On Jul 18, 2015 10:40 AM, "ahaldane" [email protected] wrote:

    A while ago I wrote up some "documentation" of how object arrays might
    work ideally, which includes various special cases and this explicit
    dtype=object change. If it's of any interest to anyone I put it up here
    https://gist.github.com/ahaldane/c3f9bcf1f62d898be7c7.

    —
    Reply to this email directly or view it on GitHub
    #5353 (comment).

  7. ahaldane commented on Jul 19, 2015

    @ahaldane
    Member

    @njsmith yeah that might be a good idea. I'll collect my thoughts for a bit and then I'll see if I can rework it into that format.

  8. charris commented on Aug 7, 2016

    @charris
    Member

    We should probably get started on this. A deprecation in array creation would be a good place to start. We might have problems with array subclasses that override __new__.

  9. charris commented on Aug 7, 2016

    @charris
    Member

    PyArray_GetArrayParamsFromObject might be the place to start, but might be too low level. It isn't called from many places. We should also decide how this interacts with ufuncs, especially with the proposed __numpy_ufunc__. Might be worth adding a temporary __not_an_array__ or some such flag that would serve temporarily to disable automatic array conversion until it is made an error.

  10. ahaldane commented on Sep 4, 2016

    @ahaldane
    Member

    I'd be happy to try some work on this sometime soon. I'm travelling for a week, but I'll take a look afterwards.

  11. ahaldane commented on Jan 17, 2017

    @ahaldane
    Member

    Followup:

    I tried implementing the new behavior (and not just the depracation) to avoid automatic object coercion by a simple modification PyArray_GetArrayParamsFromObjectas you suggested.

    It looks like a good solution! Only 9 tests fail, all of which are explicitly checking cases like variable-length lists.

    Perhaps the solution is as simple as that. I haven't thought about __new__ or ufunc issues yet, although those should already have some test coverage. Ping me when you want to speed up implementation.

  12. charris commented on Nov 17, 2018

    @charris
    Member

    Another topic for potential BIDS discussion. @stefanv Ping.

  13. added
    62 - Python APIChanges or additions to the Python API. Mailing list should usually be notified.
    on May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    62 - Python APIChanges or additions to the Python API. Mailing list should usually be notified.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions