On 03/31/2014 12:34 PM, Neal Becker wrote:
So what is this newint anyway?

I haven't looked at the code, but I would guess it's the 'long' type. I would also guess that numpy really wants an
int, not a long.

But that's all just guesses.


P.S. I'm sending directly to Neil as my ML post still hasn't shown up after a couple days.

Search Discussions

  • Ed Schofield at Apr 13, 2014 at 1:22 am
    Hi everyone,

    It seems I forgot to CC the list. Here was my reply to Neal:

    I'm just experimenting with future package.

    1st problem:
    I tried converting a small py2 module
    futurize mod.py -w

    Then I get segfault. It seems to want to do:

    from future.builtins import int

    Then when my code says:

    <some numpy container>.astype(int)

    instead of converting to int, it is converted to object.

    So what is this newint anyway?

    Thanks for your question.

    ``newint`` is simply a subclass of ``long`` on Python 2 that behaves more like Python 3?s ``int``. It?s pure-Python, so it won?t be causing any segfaults by itself. It is either NumPy or (perhaps more likely) some custom C code that is segfaulting when it gets a NumPy array of dtype object that it doesn?t handle.

    It seems that the astype method of ndarray understands ``long`` objects as a dtype on Py2 and interprets them as np.int64 objects, but it doesn?t handle subclasses of ``long``. Here is a minimal example that reproduces the problem:

    class longsubclass(long):

    def test_numpy_cast_as_long():
        import numpy as np
        a = np.arange(100, dtype=np.float64)
        b = a.astype(long)
        c = a.astype(longsubclass)
        assert b.dtype == c.dtype

    test_numpy_cast_as_long() # fails

    Ideally NumPy would be tweaked so that it interprets subclasses of the Python data types similarly to the base types.

    As a simple workaround for your code for now, you could either use <some numpy container>.astype(np.int64) or just remove the ``future.builtins.int`` import if you don?t need it. See here <http://python-future.org/what_else.html#int> for more info on what it does.

    Best wishes,

    Dr. Edward Schofield
    Python Charmers
    +61 (0)405 676 229

    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-porting/attachments/20140413/f5b01329/attachment.html>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-porting @
postedApr 1, '14 at 9:19p
activeApr 13, '14 at 1:22a

2 users in discussion

Ed Schofield: 1 post Ethan Furman: 1 post



site design / logo © 2019 Grokbase