Repository navigation
Simplify table column format definition? - #2898
Conversation
|
Would we retain back compatibility for both other formats? I do have code that sets the format. |
|
I don't see an issue with retaining backwards compatibility, and especially the |
|
OK, as long as there is no possible ambiguity between the new simplified format and the previous ones, then I'd be good with going ahead with this. |
|
@taldcroft - OK, this is now a PR. @hamogu - you may want to check whether this would take care of #2896 as well - I did try to update the documentation. |
|
Yes, that extra example is exactly what I am looking for. I like the code change that saved a lot of {}: ,too. |
There was a problem hiding this comment.
Are you sure this should be limited to ValueError? I'm always worried about some bizarre input that ends up raising a different exception in format(). So I think that here we are just checking for "this didn't work for whatever reason", try something else. But maybe you though it through and there is a reason.
|
Looks like there are some bona fide test failures for Python 3. On visual inspection I can't see why the test should be failing. |
|
Hmm, very strange that I don't get that locally. However, the underlying problem is clear (and hopefully solved with the updated PR): with a masked table and a format set, one tries to format Indeed, this is a problem generally in astropy (it just escaped testing before... now lots of tests added): |
|
@taldcroft - OK, travis passes now. But please do check again, since the new PR comes with somewhat more intrusive changes to ensure |
|
Yes, this fixes #1026; the test cases I added are quite similar to the first example there. |
There was a problem hiding this comment.
Just a niggle, but it might be conceptually cleaner to make this a function defined inside of _auto_format_func. That would also provide a better context for the comment later about "everywhere convert val to Python object...".
There was a problem hiding this comment.
One other thing, there is a slight performance penalty to making this a function instead of just inlining the expression in a few places. It might be negligible on the scale of things, not sure. OTOH this is really in the very inner loop of printing a table.
|
@mhvk - I've reviewed this and I don't see any logic problems. Somehow I feel like it might be possible to refactor the different cases into a single common basis for a cleaner code, but that's outside the scope of this PR. In any case I mostly just suggested adding comments so it's a bit easier to understand the flow. Other than that I'm good with this. |
|
And thanks for doing this, in particular picking up the long-standing #1026! |
|
Also there is the usual CHANGES.rst update, which in this case probably needs two entries, one for the new feature (added simpler way of specifying column format) and bug fix #1026. |
e17ae06 to
3c96ad9
Compare
… values. Also refactored the string tests, and added regression test against formatting of np.float32, etc. Because masked values now are OK: [closes astropy#1026]
3c96ad9 to
e8af22e
Compare
|
@taldcroft - thanks for the comments. Like you, I did feel that the code could be refactored, so I now did that, by iterating over the possible string-based format functions. I also checked speeds, and the All this means that it is probably wise to have another look... @embray - this PR now combines a bug fix [#1026] with a new feature. Your call whether it is for 1.0 or 0.4.2 (it is possible to disentangle the changes, though a bit of a pain). |
|
@mhvk - Wow, this is a great improvement! Very clever with the generator function. I'm good to go with this. @embray - if we can bend the rules just a bit and get this into 0.4.2 that would be nice. The enhancement part of this PR is strictly a back-compatible addition to the API. Of course one must confess that the bug being fixed has been around for a while and there have not been a flood of complaints... |
|
I have no problem with it. |
|
Sure. |
|
@taldcroft, @embray - OK, I moved the descriptions in the changelog to 0.4.2. Will merge now. |
Simplify table column format definition; fix printing of masked values for formatted columns
|
This is marked "affects-dev" and "affects-release". Only one of these should be used on an issue (for the way I'm using them to help organize issues). For now I'm going to assume the latter. |
|
(To clarify, "affects-dev" should be read as "affects dev only"--that is, this is not an issue that applies to any released version of Astropy). |
Simplify table column format definition; fix printing of masked values for formatted columns
Following discussion in #2896: Currently, column formats can be set by either giving a string or a function [1], with the string an old or new-style format, e.g.,
'%5.2f'or'{:5.2f}'. It would seem more logical if the user would not have to care how typesetting is done in python and could just give the actual format specifier (i.e., just'5.2f'). This would leave the string format very simple, equal to what one would guess with the most careless thought. It would also be easy to describe in the documentation, as it would just be equal to what needs to be passed in to theformatfunction. Specifically, inpprint._auto_format_func, one would the format function would be defined asinstead of the current
If the above makes sense, I'm happy to turn this into a PR. @taldcroft?
[1] http://astropy.readthedocs.org/en/latest/table/construct_table.html#format-specifier