Skip to content

Array columns error in Jupyter notebook and lab #11695

Closed

Description

@keflavich

On astropy version: 4.3.dev1429+ga832159 and 4.3.dev1484+g3f8cf27b8, in a jupyter lab environment, putting a particular table as the only item in a Jupyter Lab cell results in the following traceback and printed out table (MWE):

import numpy as np
from astropy.table import Table
Table([np.ones([10,10]), np.arange(10)])

results in both

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

~/repos/astropy/astropy/table/table.py in _repr_latex_(self)
   1549         latexdict = self.meta.get('latexdict', {})
   1550         lTable = ascii.latex.Latex(latexdict=latexdict)
-> 1551         lines = lTable.write(table=self)
   1552         self.meta['latexdict'] = lTable.latex
   1553 

~/repos/astropy/astropy/io/ascii/latex.py in write(self, table)
    338         self.header.start_line = None
    339         self.data.start_line = None
--> 340         return core.BaseReader.write(self, table=table)
    341 
    342 

~/repos/astropy/astropy/io/ascii/core.py in write(self, table)
   1474         # Check that table column dimensions are supported by this format class.
   1475         # Most formats support only 1-d columns, but some like ECSV support N-d.
-> 1476         self._check_multidim_table(table)
   1477 
   1478         # Now use altered columns

~/repos/astropy/astropy/io/ascii/core.py in _check_multidim_table(self, table)
   1282             If any column exceeds the number of allowed dimensions
   1283         """
-> 1284         _check_multidim_table(table, self.max_ndim)
   1285 
   1286     def read(self, table):

~/repos/astropy/astropy/io/ascii/core.py in _check_multidim_table(table, max_ndim)
     53     nd_names = [col.info.name for col in table.itercols() if len(col.shape) > max_ndim]
     54     if nd_names:
---> 55         raise ValueError(f'column(s) with dimension > {max_ndim} '
     56                          "cannot be be written with this format, try using 'ecsv' "
     57                          "(Enhanced CSV) format")

ValueError: column(s) with dimension > 1 cannot be be written with this format, try using 'ecsv' (Enhanced CSV) format

and

col0 [10] | col1
-- | --

1.0 .. 1.0 | 0
1.0 .. 1.0 | 1
1.0 .. 1.0 | 2
1.0 .. 1.0 | 3
1.0 .. 1.0 | 4
1.0 .. 1.0 | 5
1.0 .. 1.0 | 6
1.0 .. 1.0 | 7
1.0 .. 1.0 | 8
1.0 .. 1.0 | 9

Activity

  1. saimn commented on May 4, 2021

    @saimn
    Contributor

    Why is it using _repr_latex_ instead of _repr_html_, is that a config option in Jupyter ?

  2. pllim commented on May 4, 2021

    @pllim
    Member

    What is your jupyter --version? When it comes to Lab, maybe @mwcraig or @eteq know something.

  3. keflavich commented on May 4, 2021

    @keflavich
    ContributorAuthor
    $ jupyter --version
    jupyter core     : 4.7.0
    jupyter-notebook : 6.1.6
    qtconsole        : 4.7.7
    ipython          : 7.19.0
    ipykernel        : 5.1.4
    jupyter client   : 6.1.7
    jupyter lab      : 2.2.6
    nbconvert        : 5.6.1
    ipywidgets       : 7.6.1
    nbformat         : 5.0.8
    traitlets        : 4.3.3
    

    and

    $ jupyter --version
    jupyter core     : 4.7.1
    jupyter-notebook : 6.2.0
    qtconsole        : 5.0.2
    ipython          : 7.21.0
    ipykernel        : 5.1.2
    jupyter client   : 6.1.7
    jupyter lab      : 1.2.6
    nbconvert        : 6.0.7
    ipywidgets       : 7.6.3
    nbformat         : 5.1.2
    traitlets        : 5.0.5
    

    (I tried on both machines)

  4. pllim commented on May 4, 2021

    @pllim
    Member

    But it works in a "notebook" right?

  5. keflavich commented on May 4, 2021

    @keflavich
    ContributorAuthor

    No, the same issue occurs in a pure Notebook too (I hadn't tried that before, but I just tested and verified the result is the same)

  6. pllim commented on May 4, 2021

    @pllim
    Member

    Yeah, I tried too. Same results. Works on IPython session though. 🤷

  7. changed the title [-]Array columns error[/-] [+]Array columns error in Jupyter notebook and lab[/+] on May 4, 2021
  8. saimn commented on May 4, 2021

    @saimn
    Contributor

    Oh indeed, I get the error too on master. Bisect points to b40b22b (cc @taldcroft)

  9. taldcroft commented on May 5, 2021

    @taldcroft
    Member

    The root problem is really using _repr_latex_ instead of _repr_html_. I noticed a problem in the VS code Jupyter extension where it is doing the same thing and displaying the latex for a table. I believe if you take out the check from b40b22b then you'll get a different problem that it shows a latex table not the desired HTML. This seems like an upstream problem where it isn't choosing the cell output type properly.

  10. taldcroft commented on May 5, 2021

    @taldcroft
    Member

    I was wondering if _repr_html_ was somehow failing for a multidimensional column now and Jupyter was falling through to _repr_latex_, but seems not since the following works OK:

    from IPython.display import HTML
    HTML(Table([np.ones([10,10]), np.arange(10)])._repr_html_())
    
  11. taldcroft commented on May 5, 2021

    @taldcroft
    Member

    So I just don't understand Jupyter notebook. I took out the new check that causes problems and Jupyter runs _repr_latex_ (now successfully) but just throws away that output and moves on to _repr_html_.

    Anyway, fix coming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions