Repository navigation
Improve formatting of Table/Column.info() - #12022
Conversation
|
👋 Thank you for your draft pull request! Do you know that you can use |
nstarman
left a comment
There was a problem hiding this comment.
@eerovaher I really like this idea and it might actually be worth pushing further: v5.0 is coming up and now is the time to change the default behavior. So let's make respecting the format the new default!
|
|
||
|
|
||
| def data_info_factory(names, funcs): | ||
| def data_info_factory(names, funcs, apply_format=False): |
There was a problem hiding this comment.
Let's make apply_format=True the default!
There was a problem hiding this comment.
This code is used to enable two options for info(), which are 'attributes' and 'stats'. The default option is 'attributes', which prints the dtype, unit, format and description attributes of the columns. It doesn't make much sense to try to apply the column format to those attributes, so it is not clear that setting apply_format=True by default would be useful.
Furthermore, setting the default value to True might cause problems to anyone who might be using this factory to enable more options.
|
I'm slightly ambivalent about this since you have functions like What about formatting floating point outputs with Beyond that there are some technical problems with the current implementation.
Perhaps the right thing (if we really want to inherit the column formatting, which I'm not convinced of) would be to mimic the Then if all of those fail, fall through to no formatting. This will allow for integer formats that don't apply to floating point info values. |
|
I have to start by clarifying that calling
If the user has specified a column format that makes the values indistinguishable then it should be expected that the standard deviation would appear to be zero. If the user actually wants to use the standard deviation for something then they can still compute it and the formatting does not affect the value they obtain.
I see no reason why the user shouldn't be able to specify the formatting of the stats and using the column
I don't understand why it is necessary to try these different options, but maybe I'm just not familiar enough with string formatting. Can you provide an example that does not work with the text-based logic?
What I would propose is that the stats of a column should be formatted using the column format if it is specified. If the format is not applicable or it is not specified then applying a sensible default should be attempted. If that fails then then the code should fall back to current behavior. |
|
|
Another thing to remember is that this is user-customizable for any functions, so applying the column format won't necessarily be appropriate in those cases (as indeed it is already not appropriate for 'attributes'). I'm not too keen on the behavior of this simple convenience function getting complicated with the various fall-throughs (like going to I also think this is a bit of the tail wagging the dog, since the PR was mostly driven by the need to contrive a doc example that looks tidy and passes tests. But the table in the doc example would not normally require |
An important thing in astropy is to understand that there are a huge world of use-cases and it is important to try avoiding making assumptions based on what you believe is sensible or expected. In particular if someone chooses to format floats to the nearest int The worst case is to give an answer that appears to be definitive (e.g. |
|
There are two questions that need a definitive answer.
t.info('stats') # with default format {:g}
<Table length=5>
name mean std min max
---- ---- ------- --- ---
a 6 4.24264 0 12
b 7 4.24264 1 13
c 8 4.24264 2 14If 1. is considered to be worthwhile then it can be implemented. 2. can be implemented with or without 1. |
|
My opinion is that this is not something where we really need the flexibility / control implied by (1). For reference there is no way to configure the output format of pandas So IMO just a simple change of formatting all float outputs with Others may disagree and a free discussion here is a good thing. |
`Table.info()` and `Column.info()` now attempt to format values as
`f'{val:g}'`.
1e39fd1 to
dde38a3
Compare
|
Who is supposed to review this? |
|
@eerovaher - I'll review, though not today since I am completely tied up. Sorry for the delay, I didn't realize that there was an update. (Probably a good idea to @ mention someone if you make some progress on a PR, new commits may not get the attention of reviewers). |
taldcroft
left a comment
There was a problem hiding this comment.
Awesome, thanks @eerovaher !
Description
Suppose you happen to have a
Tablelike this:Currently
Table.info('stats')ignores the column formats:With the changes I've made to the code the column formats would be applied to the statistics too:
I am opening this pull request as a draft for initial evaluation and to present a proof of concept.
EDIT:
As a result of discussion this pull request does not allow the output of
Table.info('stats')to be formatted using theformatattribute of the table columns, but it will apply a better default formatting to numerical values instead.EDIT2 (AFTER MERGING):
Fixes #6962
Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
Extra CIlabel.no-changelog-entry-neededlabel.astropy-botcheck might be missing; do not let the green checkmark fool you.backport-X.Y.xlabel(s) before merge.