Writing simple ASCII tables broken with Numpy dev
See original GitHub issueIn the last day or so I’ve started to see the following issue with the latest developer version of Numpy:
In [2]: from astropy.table import Table
In [3]: t = Table()
In [4]: t['a'] = [1,2,3]
In [5]: t['b'] = ['a', 'b', 'c']
In [6]: t.write('test.tex', format='ascii.latex')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-b9a1187ff345> in <module>()
----> 1 t.write('test.tex', format='ascii.latex')
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/table/table.py in write(self, *args, **kwargs)
2548 passed through to the underlying data reader (e.g. `~astropy.io.ascii.write`).
2549 """
-> 2550 io_registry.write(self, *args, **kwargs)
2551
2552 def copy(self, copy_data=True):
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/io/registry.py in write(data, *args, **kwargs)
579
580 writer = get_writer(format, data.__class__)
--> 581 writer(data, *args, **kwargs)
582
583
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/io/ascii/connect.py in io_write(format, table, filename, **kwargs)
43 from .ui import write
44 format = re.sub(r'^ascii\.', '', format)
---> 45 return write(table, filename, format=format, **kwargs)
46
47
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/io/ascii/ui.py in write(table, output, format, Writer, fast_writer, **kwargs)
733 return
734
--> 735 lines = writer.write(table)
736
737 # Write the lines to output
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/io/ascii/latex.py in write(self, table)
329 self.header.start_line = None
330 self.data.start_line = None
--> 331 return core.BaseReader.write(self, table=table)
332
333
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/io/ascii/core.py in write(self, table)
1311 lines = []
1312 self.write_header(lines, table.meta)
-> 1313 self.data.write(lines)
1314
1315 return lines
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/io/ascii/latex.py in write(self, lines)
181 def write(self, lines):
182 add_dictval_to_list(self.latex, 'data_start', lines)
--> 183 core.BaseData.write(self, lines)
184 add_dictval_to_list(self.latex, 'data_end', lines)
185 lines.append(self.data_end)
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/io/ascii/core.py in write(self, lines)
829 lines.append(itertools.cycle(self.write_spacer_lines))
830
--> 831 col_str_iters = self.str_vals()
832 for vals in zip(*col_str_iters):
833 lines.append(self.splitter.join(vals))
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/io/ascii/core.py in str_vals(self)
813 def str_vals(self):
814 '''convert all values in table to a list of lists of strings'''
--> 815 self._set_fill_values(self.cols)
816 self._set_col_formats()
817 for col in self.cols:
~/miniconda3/envs/glue-dev/lib/python3.6/site-packages/astropy/io/ascii/core.py in _set_fill_values(self, cols)
787 for i, key in ((i, x) for i, x in enumerate(self.header.colnames)
788 if x in affect_cols):
--> 789 cols[i].fill_values[replacement[0]] = str(replacement[1])
790
791 def _set_masks(self, cols):
TypeError: unhashable type: 'MaskedConstant'
I’ll try and bisect.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
ASCII Tables (astropy.io.ascii) — Astropy v1.2.dev14793
astropy.io.ascii provides methods for reading and writing a wide range of ASCII data table ... Basic : basic table with customizable delimiters and...
Read more >Constructing a Table — Astropy v5.2
Format Specifier¶. The format specifier controls the output of column values when a table or column is printed or written to an ASCII...
Read more >asciitable 0.8.0 documentation
An extensible ASCII table reader and writer for Python 2 and 3. Asciitable can read and write a wide range of ASCII table...
Read more >asciitable Documentation - Read the Docs
An extensible ASCII table reader and writer for Python 2 and 3. ... reading or writing a table is largely broken into independent...
Read more >Convert Numpy array of ASCII codes to string - Stack Overflow
Another solution that does not involve leaving the NumPy world is to view the data as strings: arr = np.array([97, 98, 99], ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should be fixed by https://github.com/numpy/numpy/pull/9822 (thanks, @eric-wieser!), so I’ll close the issue.
Also cc @mhvk since you seem to enjoy these kinds of issues 😃