Astropy Table, formatting of a column with very long text
See original GitHub issueDescription
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:
- Created 3 years ago
- Comments:10 (9 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
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..info.format
works also forQuantity
inQTable
(and forTime
,SkyCoord
, etc.). ForColumn
, it just sets.format
.