thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

Allow autostrip keyword in genfromtxt (Trac #1238) #5041

Closed numpy-gitbot closed 12 years ago

numpy-gitbot commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/1238 on 2009-09-24 by atmention:jseabold, assigned to unknown.

This allows the user to specify whether the whitespace should be stripped from strings in genfromtxt. It does not change the default behavior.

This is how it was handled.

>>> from StringIO import StringIO
>>> import numpy as np
>>> s = StringIO("1/4/2003  ,1.3,abcde")
>>> data = np.genfromtxt(s, dtype=None, delimiter=',')
>>> data
array(('1/4/2003  ', 1.3, 'abcde'),
      dtype=[('f0', '|S10'), ('f1', '<f8'), ('f2', '|S5')])

Now you can do

>>> s.seek(0)
>>> data = np.genfromtxt(s, dtype=None, delimiter=',', autostrip=True)
>>> data
array(('1/4/2003', 1.3, 'abcde'),
      dtype=[('f0', '|S8'), ('f1', '<f8'), ('f2', '|S5')])

Diff file attached.

numpy-gitbot commented 12 years ago

Attachment added by atmention:jseabold on 2009-09-24: diffpatch.txt

numpy-gitbot commented 12 years ago

atmention:pierregm wrote on 2009-10-09

Can you try r7508 and report back ? Thx!

numpy-gitbot commented 12 years ago

atmention:jseabold wrote on 2009-10-09

This looks good to me.

numpy-gitbot commented 12 years ago

atmention:pierregm wrote on 2009-10-09

OK then, I'm closing the ticket