question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Astropy Table, formatting of a column with very long text

See original GitHub issue

Description

With astropy.table.Table object, using column.info.format for a str column with long text does not work as expected.

Expected behavior

I would expect it to crop the text. Or, ideally, to split it into lines with no more than the format length.

Actual behavior

For str columns with less symbols than the format length it works correctly, for columns with more symbols than the format length it does nothing.

Steps to Reproduce

Here is a code snippet:

from astropy.table import Table
a = 1
b = 'yes'
c = 'My very long description of this parameter. You have to make sure it is long enough and then try with astropy.table.Table format'

t = Table(names=['a','b','c'],dtype=('int','str','str'))
t.add_row([a,b,c])
t.pprint()
t['b'].info.format='10s'
t['c'].info.format='10s'
t.pprint()

Note that print (t) reports column b as str3 after the format change and not str10. Not sure if this is expected behaviour.

System Details

macOS-10.15.6-x86_64-i386-64bit
Python 3.8.5 (default, Sep  4 2020, 02:22:02) 
[Clang 10.0.0 ]
Numpy 1.19.2
astropy 4.1
Scipy 1.5.0
Matplotlib 3.3.2

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
taldcroftcommented, Nov 9, 2020

Sorry for being sloppy. The generic “it always works” form is .info.format. The shorthand .format only works for Column objects, and that syntax should be avoided in examples to avoid this exact confusion! My bad.

1reaction
mhvkcommented, Nov 9, 2020

.info.format works also for Quantity in QTable (and for Time, SkyCoord, etc.). For Column, it just sets .format.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing Tables — Astropy v5.2
The write() function provides a way to write a data table as a formatted ASCII table.
Read more >
Data Tables (astropy.table) — Astropy v5.2
Specify a description, units, and output formatting for columns. Interactively scroll through long tables similar to using more .
Read more >
Fixed-Width Gallery — Astropy v5.2
Fixed-width tables are those where each column has the same width for every row in the table. This is commonly used to make...
Read more >
ASCII Tables (astropy.io.ascii) — Astropy v5.2
FixedWidth : table with fixed-width columns (see also Fixed-Width Gallery) ... For reading or writing large data tables in a generic format such...
Read more >
Constructing a Table — Astropy v5.2
The Column object is derived from the standard numpy.ndarray and can be used directly ... t.write(sys.stdout, format='ascii') # Here is my explanatory text....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found