[AstroPy] Table.pprint

Aldcroft, Thomas aldcroft at head.cfa.harvard.edu
Fri Feb 26 09:18:53 EST 2021


On Fri, Feb 26, 2021 at 7:23 AM Frederic V. Hessman <
hessman at astro.physik.uni-goettingen.de> wrote:

> Tom & Thomas,
>
> Many thanks - I should have known/noticed.
>
> I note, however, that the syntax that is mentioned (in the docs in a
> different context)
>
> t['a','c']
>
> officially results in a copy of the table, which I may or may not want
> (who knows - the table might be gargantuous!), while something internal like
>
> t.pprint (['a','c'])
>
> or
>
> t.pprint (names=['a','c'])
>
> though not as elegant looking, perhaps, would permit the printing with no
> copying needed.  After all, I just want the table printed out.
>

That is a fair point about copying and something to consider.  I had the
very same thought reading through the docs, and I always wonder if "column
slicing" should behave like row slicing and return a view instead of copy.
Changing this now might not be an option, however...

There is another workaround, admittedly ugly:

>>> Table(t.columns['a', 'c'], copy=False).pprint()

- Tom


>
> Re docs: I would still add more examples to the docs to emphasize the
> range of options, something like
>
>
> *Print table or column*
>
> print(t)     # Print formatted version of table to the screent.pprint()   # Same as abovet.pprint(show_unit=True)  # Show column unitt.pprint(show_name=False)  # Do not show column namest.pprint_all() # Print full table no matter how long / wide it is (same as t.pprint(max_lines=-1, max_width=-1))
> t.more()  # Interactively scroll through table like Unix "more"
> print(t['a'])    # Formatted column valuest['a'].pprint()  # Same as above, with same options as Table.pprint()t['a'].more()    # Interactively scroll through column
> t['a','b'].more() # Interactively scroll 2 columns (also works with pprint)
>
>
> at the top (for obivously superficial readers like myself) and below
>
> Hiding columns
> <https://docs.astropy.org/en/latest/table/access_table.html#hiding-columns>
>
> The Table
> <https://docs.astropy.org/en/latest/api/astropy.table.Table.html#astropy.table.Table> class
> has two ways to selectively show certain columns when using any of the
> print methods. For simple cases, use the standard syntax
>
> t['col1','col999'].pprint()
>
> (a copy of the table is made).  For more formal or complicated cases,
> using the functionality to consistently show or hide certain columns within
> the table. The latter method can be useful for columns that are very wide
> or else “uninteresting” for various reasons. ...
>
> Again, many thanks!
>
> Rick
>
> On 26 Feb 2021, at 12:31, Aldcroft, Thomas <aldcroft at head.cfa.harvard.edu>
> wro
>
> te:
>
> Indeed `tabl['col1', 'col99'].pprint()` is the right idiom for printing a
> subset of columns. I see the docs didn't include anything quite like that,
> so I added an example. See:
>   https://github.com/astropy/astropy/pull/11354.
>
> BTW, starting with the next release of astropy (4.3) you can persistently
> include or exclude selected column names from being printed. This can be
> helpful if you have a table that has some uninteresting columns, or perhaps
> a very wide column that dominates printing. See:
>
> https://docs.astropy.org/en/latest/table/access_table.html#hiding-columns
>
> - Tom
>
>
> On Fri, Feb 26, 2021 at 4:45 AM Thomas Boch <thomas.boch at astro.unistra.fr>
> wrote:
>
>> Hi Rick,
>>
>> What about:
>>
>> tabl['col1', 'col99'].pprint()
>>
>> ?
>>
>> Cheers,
>>
>> Thomas
>>
>> Le 26/02/2021 à 09:54, Frederic V. Hessman a écrit :
>> > Surely there's a simple way to pprint only selected columns of a table,
>> something like
>> >
>> >>>> tabl.pprint (names=['col1','col99'])
>> > but I haven't seen anything obvious.  Yes, there are brute force
>> work-arounds, but....
>> >
>> > Rick
>> > _______________________________________________
>> > AstroPy mailing list
>> > AstroPy at python.org
>> > https://mail.python.org/mailman/listinfo/astropy
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at python.org
>> https://mail.python.org/mailman/listinfo/astropy
>>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20210226/451712ee/attachment.html>


More information about the AstroPy mailing list