Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion larry indexing breaks for dtype=object due to numpy isscalar call

Received: by 10.50.47.132 with SMTP id d4mr3461016ign.1.1327707445815;
        Fri, 27 Jan 2012 15:37:25 -0800 (PST)
X-BeenThere: labeled-array@googlegroups.com
Received: by 10.50.42.161 with SMTP id p1ls8707324igl.1.gmail; Fri, 27 Jan
 2012 15:37:25 -0800 (PST)
Received: by 10.50.46.194 with SMTP id x2mr4416150igm.2.1327707445555;
        Fri, 27 Jan 2012 15:37:25 -0800 (PST)
Received: by 10.50.46.194 with SMTP id x2mr4416149igm.2.1327707445546;
        Fri, 27 Jan 2012 15:37:25 -0800 (PST)
Return-Path: <thomasmcof...@gmail.com>
Received: from mail-tul01m020-f173.google.com (mail-tul01m020-f173.google.com [209.85.214.173])
        by gmr-mx.google.com with ESMTPS id cg4si3166837igb.0.2012.01.27.15.37.25
        (version=TLSv1/SSLv3 cipher=OTHER);
        Fri, 27 Jan 2012 15:37:25 -0800 (PST)
Received-SPF: pass (google.com: domain of thomasmcof...@gmail.com designates 209.85.214.173 as permitted sender) client-ip=209.85.214.173;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of thomasmcof...@gmail.com designates 209.85.214.173 as permitted sender) smtp.mail=thomasmcof...@gmail.com; dkim=pass header...@gmail.com
Received: by obbup16 with SMTP id up16so3202777obb.18
        for <labeled-array@googlegroups.com>; Fri, 27 Jan 2012 15:37:25 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=gamma;
        h=mime-version:from:date:message-id:subject:to:content-type;
        bh=m4+EuzBneu5Zapshb2YiDYkcMWGNEI/O9EqIchg4PnI=;
        b=pQqJQDV59rDr+u4b2S0YS5U/IKfPCS5ntivr8qBgjzNIsAFk1KteghruEmKX/Dh3+x
         rI8jojfp5kfgMtdNU+BLmYaUD+UsNC92IqtJ0HsrycWEIpzsDPMcUgFCAP+RvjmEfjSS
         tbR+q57CwrF2K6EDneQu15PFpFL+dUguE2+fA=
Received: by 10.182.160.5 with SMTP id xg5mr8397374obb.53.1327707445201; Fri,
 27 Jan 2012 15:37:25 -0800 (PST)
MIME-Version: 1.0
Received: by 10.182.10.101 with HTTP; Fri, 27 Jan 2012 15:37:05 -0800 (PST)
From: Thomas Coffee <thomasmcof...@gmail.com>
Date: Fri, 27 Jan 2012 18:37:05 -0500
Message-ID: <CADbDyG+AKL86i8=3oasWRwphHPDYRW5G_n2AAkTuGBopxP6PVw@mail.gmail.com>
Subject: larry indexing breaks for dtype=object due to numpy isscalar call
To: labeled-array@googlegroups.com
Content-Type: text/plain; charset=UTF-8

For instance, the following object-dtype larry does not index properly:

>>> class C:
...     pass
...
>>> c = larry([C()])
>>> c[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "la/deflarry.py", line 1719, in __getitem__
    return larry(x, label)
  File "la/deflarry.py", line 116, in __init__
    raise ValueError, '0d larrys are not supported'
ValueError: 0d larrys are not supported


Whereas a numerical larry does:

>>> z = larry([0])
>>> z[0]
0


I believe the reason is that the larry.__getitem__ implementation
determines the dimension of the result of the indexing call by calling
numpy.isscalar on the result, which returns False for a generic object
(deflarry.py: line 1717).

I am not sure what is necessary to ensure the correct behavior always,
but in my case, the problem can be fixed by inserting the lines

            if self.ndim <= 1:
                return x

before line 1645, at the end if the clause "if isscalar(index):" in
the definition of larry.__getitem__.