Skip to content

Define format_func for columns on info? #5804

Closed

Description

@mhvk

Just so we do not loose track of a possibility discussed in #5800 for how to deal with formats for table columns. Currently, one can set <col>.info.format and this gets used in printing the table, by creating a custom format function that uses the format given (which can be old or new or shortened style). The printing machinery caches these functions as they are relatively expensive to create and one doesn't want to recreate them for every element of a column. It would seem perhaps more logical to move this logic to the column itself, i.e., that info stores also the formatting function. In principle, this function could even be created when one sets format, though this would have to work around the case where the column does not yet have any data associated with it.

Activity

  1. mhvk commented on Oct 10, 2017

    @mhvk
    ContributorAuthor

    Adding the bug label since the current implementation causes problems (#6703). In #6703, @larrybradley noted that if one were to create the format function only at the point one was actually trying to format the column, there would not ever be an issue with there being no data.

    Overall, I would envisage an implementation where there is a some function (perhaps just __format__) which creates and caches a print function when called (except when first element is masked/NaN), and the cache would get deleted whenever col.info.format is set.

  2. neutrinoceros commented on Dec 6, 2023

    @neutrinoceros
    Contributor

    #6703 was closed in astropy 3.0, do you think the bug label is still relevant @mhvk ?

  3. mhvk commented on Dec 6, 2023

    @mhvk
    ContributorAuthor

    @neutrinoceros - you are right, this was solved in #6714, and that in fact used the suggestion given here to store the format function on col.info. So, this one can be closed. Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions