[Numpy-discussion] loadtxt and usecols
sebastian at sipsolutions.net
Wed Nov 11 12:38:50 EST 2015
On Di, 2015-11-10 at 17:39 +0100, Irvin Probst wrote:
> On 10/11/2015 16:52, Daπid wrote:
> > ((((42,)))) is exactly the same as (42,) If you want a tuple of
> > tuples, you have to do ((42,),), but then it raises: TypeError: list
> > indices must be integers, not tuple.
> My bad, I wrote that too fast, please forget this.
> > I think loadtxt should be a tool to read text files in the least
> > surprising fashion, and a text file is a 1 or 2D container, so it
> > shouldn't return any other shapes.
> And I *do* agree with the "shouldn't return any other shapes" part of
> your phrase. What I was trying to say, admitedly with a very bogus
> example, is that either loadtxt() should always output an array whose
> shape matches the shape of the object passed to usecol or it should
> never do it, and I'm if favor of never.
Sounds fine to me, and considering the squeeze logic (which I think is
unfortunate, but it is not something you can easily change), I would be
for simply adding logic to accept a single integral argument and
otherwise not change anything.
I am personally against the flattening and even the array-like logic 
currently in the PR, it seems like arbitrary generality for my taste
without any obvious application.
As said before, the other/additional thing that might be very helpful is
trying to give a more useful error message.
 Almost all 1-d array-likes will be sequences/iterables in any case,
those that are not are so obscure that there is no point in explicitly
> I'm perfectly aware that what I suggest would break the current behavior
> of usecols=(2,) so I know it does not have the slightest probability of
> being accepted but still, I think that the "least surprising fashion" is
> to always return an 2-D array because for many, many, many people a text
> data file has N lines and M columns and N=1 or M=1 is not a specific case.
> Anyway I will of course modify my PR according to any decision made here.
> In your example:
> > a=[[[2,],,,],,,]
> > foo=np.loadtxt("CONCARNEAU_2010.txt", usecols=a)
> > What would the shape of foo be?
> As I said in my previous email:
> > should just work and return me a 2-D (or 1-D if you like) array with
> the data I asked for
> So, 1-D or 2-D it is up to you, but as long as there is no ambiguity in
> which columns the user is asking for it should imho work.
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: This is a digitally signed message part
More information about the NumPy-Discussion