A Dimarts 13 Febrer 2007 19:49, escriguéreu:
> Hello Francesc.
>
> >Mmm, after considering this a bit more seriously, I think that I'll go
>
> towards
>
> >implementing the alternative:
> >
> >row.fetch_all_fields()
> >
> >because:
> >
> >- It would be simpler and more efficient to implement (i.e.
> > Row.__getitem__ will not be cluttered with more logic).
> >
> >- Accepting a [:] would make users think that complete extended slicing
>
> suport
>
> >(like [colstart:colstop:colstep]) would be implemented and it will be not
>
> (at
>
> >least initially).
>
> I think that slicing is very easy to implement if we have something like
> fetch_all_fields which will return a list:
>
> def __getslice__(self, a, b):
>   return self.fetch_all_fields().__getslice__(a,b)
>
> , so both ways can be implemented at once.

That would be nice, but unfortunately, things are not so easy.

First, __getslice__() is deprecated, so I'll assume that you mean __getitem__.

Second, NumPy doesn't support slices (even not integers!) in scalar record 
types (the kind of values I'm thinking to be returned 
by .fetch_all_fields()), as can be seen in:

In [54]: a=numpy.array((1,2,"asa"), "i2,i2,a3")

In [55]: a['f0']   # name fields are the only indexes allowed
Out[55]: 1

In [56]: a[1]
---------------------------------------------------------------------------
<type 'exceptions.IndexError'>            Traceback (most recent call last)

/home/faltet/python.nobackup/Pyrex-0.9.5.1a/<ipython console> in <module>()

<type 'exceptions.IndexError'>: 0-d arrays can't be indexed

In [57]: a[:]
---------------------------------------------------------------------------
<type 'exceptions.ValueError'>            Traceback (most recent call last)

/home/faltet/python.nobackup/Pyrex-0.9.5.1a/<ipython console> in <module>()

<type 'exceptions.ValueError'>: cannot slice a 0-d array


And thirdly, even though NumPy would eventually support a generalized slicing 
for scalar records, Row.__getitem__ is very carefully tuned (i.e. it has low 
level logic inside) for dealing only with field names. So, just doing things 
like:

return self.fetch_all_fields().__getitem__(...)

is a simplistic aproximation that would render unusable many of the existing 
optimizations in Row.__getitem__().

Cheers,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to