Skip to content

Instantly share code, notes, and snippets.

@mwcraig
Created September 13, 2013 05:39
Show Gist options
  • Save mwcraig/6547072 to your computer and use it in GitHub Desktop.
Save mwcraig/6547072 to your computer and use it in GitHub Desktop.
astropy masked Table print/repr error traceback
In [1]: from astropy.table import Table
In [2]:
In [2]: numbers = [1, 2, 3]
In [3]: strings = ['a', 'b', 'c']
In [4]:
In [4]: t_mask_numbers = Table(data=[numbers], masked=True)
In [5]: comparison_numbers_masked = (t_mask_numbers['col0'] == 1)
In [6]: type(comparison_numbers_masked) # this is a MaskedColumn object
Out[6]: astropy.table.table.MaskedColumn
In [7]: comparison_numbers_masked # that causes an error on display...
Out[7]: ERROR: TypeError: object of type 'NoneType' has no len() [astropy.table.pprint]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-cfa1fbfa9478> in <module>()
----> 1 comparison_numbers_masked # that causes an error on display...
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result)
245 self.start_displayhook()
246 self.write_output_prompt()
--> 247 format_dict, md_dict = self.compute_format_data(result)
248 self.write_format_data(format_dict, md_dict)
249 self.update_user_ns(result)
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
155
156 """
--> 157 return self.shell.display_formatter.format(result)
158
159 def write_format_data(self, format_dict, md_dict=None):
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/IPython/core/formatters.pyc in format(self, obj, include, exclude)
150 md = None
151 try:
--> 152 data = formatter(obj)
153 except:
154 # FIXME: log the exception
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
479 type_pprinters=self.type_printers,
480 deferred_pprinters=self.deferred_printers)
--> 481 printer.pretty(obj)
482 printer.flush()
483 return stream.getvalue()
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
360 if callable(meth):
361 return meth(obj, self, cycle)
--> 362 return _default_pprint(obj, self, cycle)
363 finally:
364 self.end_group()
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
480 if getattr(klass, '__repr__', None) not in _baseclass_reprs:
481 # A user-provided repr.
--> 482 p.text(repr(obj))
483 return
484 p.begin_group(1, '<')
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/astropy/table/table.pyc in __repr__(self)
198 self.__class__.__name__,
199 repr(self.name), repr(units),
--> 200 repr(self.format), repr(self.description), repr(self.data))
201
202 return out
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/numpy/ma/core.pyc in __repr__(self)
3551 name = repr(self._data).split('(')[0]
3552 parameters = dict(name=name, nlen=" " * len(name),
-> 3553 data=str(self), mask=str(self._mask),
3554 fill=str(self.fill_value), dtype=str(self.dtype))
3555 if self.dtype.names:
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/numpy/ma/core.pyc in __str__(self)
3542 else:
3543 res = self.filled(self.fill_value)
-> 3544 return str(res)
3545
3546 def __repr__(self):
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/astropy/table/table.pyc in __str__(self)
380
381 def __str__(self):
--> 382 lines, n_header = _pformat_col(self)
383 return '\n'.join(lines)
384
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/astropy/table/pprint.pyc in _pformat_col(col, max_lines, show_name, show_units)
130 outs = {} # Some values from _pformat_col_iter iterator that are needed here
131 col_strs = list(_pformat_col_iter(col, max_lines, show_name, show_units, outs))
--> 132 col_width = max(len(x) for x in col_strs)
133
134 # Center line content and generate dashed headerline
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/astropy/table/pprint.pyc in <genexpr>((x,))
130 outs = {} # Some values from _pformat_col_iter iterator that are needed here
131 col_strs = list(_pformat_col_iter(col, max_lines, show_name, show_units, outs))
--> 132 col_width = max(len(x) for x in col_strs)
133
134 # Center line content and generate dashed headerline
TypeError: object of type 'NoneType' has no len()
In [8]: print (comparison_numbers_masked) # ...but can be printed!
col0
-----
True
False
False
In [9]:
In [9]: t_mask_strings = Table(data=[strings], masked=True)
In [10]: comparison_strings_masked = (t_mask_strings['col0'] == 'a')
In [11]: type(comparison_strings_masked) # this is a MaskedColumn object
Out[11]: astropy.table.table.MaskedColumn
In [12]: comparison_strings_masked # that can be displayed...
Out[12]:
<MaskedColumn name=None units=None format=None description=None>
masked_array(data = [True False False],
mask = [False False False],
fill_value = True)
In [13]: print (comparison_strings_masked) # ...but not printed!
ERROR: TypeError: object of type 'NoneType' has no len() [astropy.table.pprint]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-fde1e38365c6> in <module>()
----> 1 print (comparison_strings_masked) # ...but not printed!
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/astropy/table/table.pyc in __str__(self)
380
381 def __str__(self):
--> 382 lines, n_header = _pformat_col(self)
383 return '\n'.join(lines)
384
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/astropy/table/pprint.pyc in _pformat_col(col, max_lines, show_name, show_units)
130 outs = {} # Some values from _pformat_col_iter iterator that are needed here
131 col_strs = list(_pformat_col_iter(col, max_lines, show_name, show_units, outs))
--> 132 col_width = max(len(x) for x in col_strs)
133
134 # Center line content and generate dashed headerline
/Users/mcraig/anaconda/python.app/Contents/lib/python2.7/site-packages/astropy/table/pprint.pyc in <genexpr>((x,))
130 outs = {} # Some values from _pformat_col_iter iterator that are needed here
131 col_strs = list(_pformat_col_iter(col, max_lines, show_name, show_units, outs))
--> 132 col_width = max(len(x) for x in col_strs)
133
134 # Center line content and generate dashed headerline
TypeError: object of type 'NoneType' has no len()
In [14]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment