astropy/astropy — pull request #909 by hamogu (2013-04-09 22:57:27+00:00)
Title: astropy.io.ascii.write no longer accepts formatting functions

`astropy.io.ascii.write` used to accept functions to format a string value in the `formats = {}` dictionary. This is particulalry helpful for LaTeX output, when e.g. certain LeTeX signs need to be added to.
Below is a minimal example that is taken almost exactly from the documentation
http://docs.astropy.org/en/v0.2/io/ascii/write.html#parameters-for-write

```
In [1]: import astropy

In [2]: import astropy.io

In [3]: import astropy.io.ascii

In [4]: data2 = {'x': [1, 2, 3], 'y': [4, 5.2, 6.1], 'z': ['hello', 'world', '!!!']}

In [5]: astropy.io.ascii.write(data2, sys.stdout, formats={'x': '12.1f', 'y': lambda x: round(x, 1)})
ERROR: ValueError: Unable to parse format string at 0x5036c08> [astropy.table.pprint]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 astropy.io.ascii.write(data2, sys.stdout, formats={'x': '12.1f', 'y': lambda x: round(x, 1)})

/data/guenther/astrosoft/astropy/astropy/io/ascii/ui.pyc in write(table, output, Writer, **kwargs)
276
277 writer = get_writer(Writer=Writer, **kwargs)
--> 278 lines = writer.write(table)
279
280 # Write the lines to output

/data/guenther/astrosoft/astropy/astropy/io/ascii/core.pyc in write(self, table)
910 lines = []
911 self.header.write(lines)
--> 912 self.data.write(lines)
913
914 return lines

/data/guenther/astrosoft/astropy/astropy/io/ascii/core.pyc in write(self, lines)
593 with self._set_col_formats(self.cols, self.formats):
594 col_str_iters = [col.iter_str_vals() for col in self.cols]
--> 595 for vals in izip(*col_str_iters):
596 lines.append(self.splitter.join(vals))
597

/data/guenther/astrosoft/astropy/astropy/table/table.pyc in iter_str_vals(self)
204 # Iterate over formatted values with no max number of lines, no column
205 # name, no units, and ignoring the returned header info in outs.
--> 206 for str_val in _pformat_col_iter(self, -1, False, False, {}):
207 yield str_val
208

/data/guenther/astrosoft/astropy/astropy/table/pprint.pyc in _pformat_col_iter(col, max_lines, show_name, show_units, outs)
212 format_func(col.format, col[(i,) + multidim1]))
213 else:
--> 214 col_str = format_func(col.format, col[i])
215 yield col_str
216 elif i == i0:

/data/guenther/astrosoft/astropy/astropy/table/pprint.pyc in _auto_format_func(format_, val)
100 except:
101 raise ValueError('Unable to parse format string {0}'
--> 102 .format(format_))
103 _format_funcs[format_] = format_func
104 return out

ValueError: Unable to parse format string at 0x5036c08>
```