Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24547
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!204.52.135.9.MISMATCH!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'class,': 0.07; 'constructor': 0.07; 'suppose': 0.07; 'subject:question': 0.08; '__init__': 0.09; 'expected.': 0.09; 'grid': 0.09; "object's": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subclass': 0.09; 'underlying': 0.09; 'unexpected': 0.09; 'def': 0.10; 'deprecation': 0.16; 'explicitly.': 0.16; 'instantiate': 0.16; 'kern': 0.16; 'message- id:@dough.gmane.org': 0.16; 'numpy': 0.16; 'personally,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'stuff)': 0.16; 'subclassing': 0.16; 'wrote:': 0.17; '>>>': 0.18; '(not': 0.20; 'parameters': 0.20; 'trying': 0.21; 'import': 0.21; 'interpret': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; 'this?': 0.28; 'all.': 0.28; 'arguments.': 0.29; 'points': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "i'm": 0.29; 'skip:8 10': 0.32; 'running': 0.32; 'could': 0.32; 'handle': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'skip:d 20': 0.34; 'jason': 0.35; 'robert': 0.35; 'doing': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'list.': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'does': 0.37; '(for': 0.37; 'rather': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'url:docs': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'hello,': 0.39; 'header:Received:5': 0.40; 'subject:, ': 0.61; 'provide': 0.62; 'skip:6 10': 0.63; 'world': 0.63; 'skip:n 10': 0.63; 'within': 0.64; 'our': 0.65; 'taking': 0.65; 'subject:skip:D 10': 0.65; 'believe': 0.69; 'hoping': 0.72; 'eco': 0.84; 'presumably': 0.84; 'terrible': 0.84; 'writing,': 0.84; 'received:86': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Robert Kern <robert.kern@gmail.com> |
| Subject | Re: question about numpy, subclassing, and a DeprecationWarning |
| Date | Wed, 27 Jun 2012 22:57:39 +0100 |
| References | <CAEk9e3qQQL2RZZZHQZdri9B026Av2HWniMBbP6KbgARQMO2c+A@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | cpc24-cmbg15-2-0-cust204.5-4.cable.virginmedia.com |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 |
| In-Reply-To | <CAEk9e3qQQL2RZZZHQZdri9B026Av2HWniMBbP6KbgARQMO2c+A@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1568.1340834275.4697.python-list@python.org> (permalink) |
| Lines | 59 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1340834275 news.xs4all.nl 6970 [2001:888:2000:d::a6]:35527 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:24547 |
Show key headers only | View raw
On 6/27/12 10:02 PM, Jason Swails wrote: > Hello, > > I'm running into an unexpected issue in a program I'm writing, and I was hoping > someone could provide some clarification for me. I'm trying to subclass > numpy.ndarray (basically create a class to handle a 3D grid). When I > instantiate a numpy.ndarray, everything works as expected. When I call > numpy.ndarray's constructor directly within my subclass, I get a deprecation > warning about object.__init__ not taking arguments. Presumably this means that > ndarray's __init__ is somehow (for some reason?) calling object's __init__... > > This is some sample code: > > >>> import numpy as np > >>> class derived(np.ndarray): > ... def __init__(self, stuff): > ... np.ndarray.__init__(self, stuff) > ... > >>> l = derived((2,3)) > __main__:3: DeprecationWarning: object.__init__() takes no parameters > >>> l > derived([[ 8.87744455e+159, 6.42896975e-109, 5.56218818e+180], > [ 1.79996515e+219, 2.41625066e+198, 5.15855295e+307]]) > >>> > > Am I doing something blatantly stupid? Is there a better way of going about > this? I suppose I could create a normal class and just put the grid points in a > ndarray as an attribute to the class, but I would rather subclass ndarray > directly (not sure I have a good reason for it, though). Suggestions on what I > should do? numpy.ndarray does not have its own __init__(), just a __new__(). It's __init__() is the same as object.__init__(), which takes no arguments. [~] |3> np.ndarray.__init__ is object.__init__ True There is no need to call np.ndarray.__init__() explicitly. http://docs.scipy.org/doc/numpy/user/basics.subclassing.html#a-brief-python-primer-on-new-and-init You will also want to ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists Personally, I recommend not subclassing ndarray at all. It rarely works out well. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: question about numpy, subclassing, and a DeprecationWarning Robert Kern <robert.kern@gmail.com> - 2012-06-27 22:57 +0100
csiph-web