neuroradiology / prettytable

Automatically exported from code.google.com/p/prettytable
Other
0 stars 0 forks source link

Round col entries to number of significant figures #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Is this something that has being considered for future versions?  It'd be 
really nice if a format spec could be supplied for the formatting of all floats 
in a column or table e.g.

my_pretty_table.float_format_spec("4.2")

Original issue reported on code.google.com by willfurn...@gmail.com on 28 Feb 2012 at 11:22

GoogleCodeExporter commented 8 years ago
Agreed.

Original comment by jadol...@gmail.com on 21 Mar 2012 at 5:30

GoogleCodeExporter commented 8 years ago
Hi,

Thanks for the suggestion.  I agree that this would be a nice feature, and it 
doesn't seem too hard.  I will have a go at implementing it shortly.  For now 
I'll probably just go with one format spec for all columns rather than a 
per-column setting, just because I have a lot of feature requests which have 
piled up and I want to try to make fast progress on them.  But upgrading to a 
per-column setting later is a definite possibility.

Cheers,
Luke

Original comment by luke@maurits.id.au on 23 Mar 2012 at 3:55

GoogleCodeExporter commented 8 years ago
Hi,

I have just committed to the trunk of the svn repo with an implementation of 
this.  I would appreciate it very much if the people who have commented on this 
issue could give the new version a test and confirm whether or not it meets 
their needs.  Note, however, that if you have been using PrettyTable 0.5 until 
now, the API in the trunk version is substantially different.  Check out this 
Wiki page for instructions on how the new, cleaner API works: 
http://code.google.com/p/prettytable/wiki/Tutorial06

To set a floating point format for a PrettyTable object, just use:

MyTable.float_format = "4.2"

to print things using "%4.2f".  You can also do 04.2 to pad with leading 0s, 
etc.

Original comment by luke@maurits.id.au on 24 Mar 2012 at 2:53

GoogleCodeExporter commented 8 years ago
Working well for me.  Thanks for adding the feature.  Per-column formats would 
be great.  

Original comment by willfurn...@gmail.com on 27 Mar 2012 at 12:47

GoogleCodeExporter commented 8 years ago
Per-column formatting is now supported in the trunk version.  It works like 
this:

table.float_format["Foo"] = "4.2"
table.float_format["Bar"] = "2.4"
table.float_format["Baz"] = "123.321"

If you try to use the old style syntax and do:

table.float_format = "4.2"

then this will set a format of "4.2" to all columns, over-writing any 
per-column formatting you previously set up.

If you are interested in per-column formatting, please try to give this a test 
soon.  If I do not hear of any bugs with the new per-column formatting in a few 
days I will close this ticket, since I'm trying to get a clean Issue page to 
release 0.6, and people will have to open a new one to report bugs.

Original comment by luke@maurits.id.au on 1 May 2012 at 4:54

GoogleCodeExporter commented 8 years ago
Forgot to mention - there is now similar support for integer formatting strings 
with the same interface as float formatting, e.g.

table.int_format["Foo"] = "05"

will print any integer data in the "Foo" column padded out to 5 characters with 
leading zeros.

Original comment by luke@maurits.id.au on 1 May 2012 at 4:59

GoogleCodeExporter commented 8 years ago
Closing this issue since float formatting is now implemented and available on a 
per-column basis, and I've received no bug reports or negative feedback.  If 
anybody has float formatting requirements in the future which PrettyTable 
doesn't support, feel free to open a new ticket.

Original comment by luke@maurits.id.au on 4 May 2012 at 6:18