astropy: ``Column.pprint`` fails for scalars

Description

Raises TypeError because object is scalar and the code expects an array object.

Expected behavior

If it can be made into a Column, pprint works.

Actual behavior

See Description.

Steps to Reproduce

import astropy.units as u
from astropy.table import Column

Column(1).pprint()

TypeError: len() of unsized object

System Details

macOS-10.16-x86_64-i386-64bit Python 3.9.5 (default, May 18 2021, 12:31:01) [Clang 10.0.0 ] Numpy 1.21.4 pyerfa 2.0.0.1 astropy 5.1.dev207+gbfb9252df.d20211130 Scipy 1.7.1 Matplotlib 3.3.4

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 16 (13 by maintainers)

Most upvoted comments

@tactipus We’re working on a fix in the linked PR #15749

However, I’ve confirmed that not allowing Column to be initialized with a scalar does indeed create problems in astropy code that are not immediately trivial. This suggests that user code might break as well, so it looks like #15749 is the better choice if it doesn’t impact performance.

@mhvk sorry I opened #15754 before I saw your comment, I just noticed that independently and assumed it could be considered a bug. If you believe that behaviour to be desirable feel free to close my issue !

@tactipus My pull request is publicly available. Actually by now I think I figured it out !

I’ve opened #15749 to attempt to fix this. I went with what felt like the most natural approach (also suggested by @nstarman) to special-case scalar columns. The patch is really small at the moment but it’s not completely functional as it breaks at least one existing test. Feedback and suggestions are most welcome !