diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py index 083e13e36c7d..cc2811438798 100644 --- a/lib/matplotlib/mlab.py +++ b/lib/matplotlib/mlab.py @@ -2867,14 +2867,20 @@ def get_func(name, item, func): 'print': 'print_', } - def get_converters(reader): + def get_converters(reader, comments): converters = None - for i, row in enumerate(reader): + i = 0 + for row in reader: + if (len(row) and comments is not None and + row[0].startswith(comments)): + continue if i == 0: converters = [mybool]*len(row) if checkrows and i > checkrows: break + i += 1 + for j, (name, item) in enumerate(zip(names, row)): func = converterd.get(j) if func is None: @@ -2925,7 +2931,7 @@ def get_converters(reader): names = [n.strip() for n in names.split(',')] # get the converter functions by inspecting checkrows - converters = get_converters(reader) + converters = get_converters(reader, comments) if converters is None: raise ValueError('Could not find any valid data in CSV file') diff --git a/lib/matplotlib/tests/test_mlab.py b/lib/matplotlib/tests/test_mlab.py index 51652a49ef52..71d3a92aec37 100644 --- a/lib/matplotlib/tests/test_mlab.py +++ b/lib/matplotlib/tests/test_mlab.py @@ -339,6 +339,13 @@ def test_rec2csv_bad_shape_ValueError(self): # the bad recarray should trigger a ValueError for having ndim > 1. assert_raises(ValueError, mlab.rec2csv, bad, self.fd) + def test_csv2rec_names_with_comments(self): + self.fd.write('# comment\n1,2,3\n4,5,6\n') + self.fd.seek(0) + array = mlab.csv2rec(self.fd, names='a,b,c') + assert len(array) == 2 + assert len(array.dtype) == 3 + class window_testcase(CleanupTestCase): def setUp(self):