[SciPy-Dev] np.savetxt: apply patch in enhancement ticket 1079 to add headers?

Stefan stefan.czesla at hs.uni-hamburg.de
Tue Jun 1 13:05:19 EDT 2010


Skipper Seabold <jsseabold <at> gmail.com> writes:

> 
> Hi all,
> 
> I am assuming that this is ok to request via the list...  Could we
> discuss or could someone apply the patch in enhancement ticket 1079?
> 
> http://projects.scipy.org/numpy/ticket/1079
> 
> I needed this functionality recently, and this is a quick and easy fix
> that may have been overlooked.
> 
> There is also another enhancement request about this here:
> http://projects.scipy.org/numpy/ticket/1236
> 
> The only thing that I can think of that might need to be added is a
> test to see that the header length is the same as the number of
> columns, but really that might just be up to the user to supply the
> right headers.  It might also be nice to have a header = True, that
> uses the field names for a structured array, but I can live without
> that.
> 
> Cheers,
> 
> Skipper
> 

Hi,

+1; we have the same problem quite frequently. Our current solution looks
similar to what has been proposed in ticket 1079, and we wonder why a solution
has not yet found its way into the official release of numpy.

We can, however, image a slightly different implementation and would like to
hear the community's opinion on it.

If the header is given as a plane string (such as envisaged in ticket 1079), the
user has to care for the correct formatting, in particular, the user has to
supply the comment character(s) and the new line formatting. This might be
against intuition, because many users will at first try to supply their
header(s) without specifying those formatting characters. The result will be a
file not readable with numpy.loadtxt, and the error might not be detected right
away.

As numpy.loadtxt has a default comment character ('#'), the same may be
implemented for numpy.savetxt. In this case, numpy.savetxt would get two
additional keywords (e.g. header, comment(character)), which bloats the
interface, but potentially provides more safety.

Cheers,
Stefan & Christian





More information about the SciPy-Dev mailing list