Opened 5 years ago

Closed 5 years ago

#14601 closed defect (fixed)

table.__repr__() replaces True and False by 1 and 0

Reported by: slabbe Owned by: jason
Priority: major Milestone: sage-5.10
Component: misc Keywords:
Cc: Merged in: sage-5.10.beta5
Authors: John Palmieri Reviewers: Sébastien Labbé
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #13131 Stopgaps:

Description

Using sage-5.8 with #13131 merged in sage-5.10.beta0, I get

sage: table([('a','b','c'), (True, False,None)]) 
  a      b       c                               
  1      0       None                            

I was expecting :

sage: table([('a','b','c'), (True, False,None)]) 
  a      b       c                               
  True   False   None                            

Attachments (1)

trac_14601-table.patch (1.5 KB) - added by jhpalmieri 5 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by jhpalmieri

Maybe the calls to format should include !s in the string? As in

  • sage/misc/table.py

    a b  
    500500            widths = widths[1:]
    501501
    502502        for (entry, width) in zip(row, widths):
    503             s += ("{:" + align_char + str(width) + "}").format(entry)
     503            s += ("{!s:" + align_char + str(width) + "}").format(entry)
    504504            if frame:
    505505                s += " | "
    506506            else:

and another similar change. (Untested.)

Last edited 5 years ago by jhpalmieri (previous) (diff)

comment:2 Changed 5 years ago by slabbe

I did not know about this !s I have never used this format syntax for strings...

Related to this same line, I got the following deprecation warning when I called table the first time in my session :

/Users/slabbe/Applications/sage-5.8/local/lib/python2.7/site-packages/sage/misc/table.py:503:
PendingDeprecationWarning: object.__format__ with a non-empty format string is deprecated
  s += ("{:" + align_char + str(width) + "}").format(entry)

Do you get such warning also?

UPDATE : I am not able to reproduce the warning...

Last edited 5 years ago by slabbe (previous) (diff)

comment:3 Changed 5 years ago by slabbe

After reading http://docs.python.org/2/library/string.html

and doing some tests, I now understand your suggestion :

sage: ("{:^10}").format(False)  
'    0     '        
sage: ("{!s:^10}").format(False)
'  False   '                    
sage: ("{!r:^10}").format(False)
'  False   '   
sage: ("{:^10}").format(None)   
'   None   '                    
sage: ("{!s:^10}").format(None) 
'   None   '                    
sage: ("{!r:^10}").format(None) 
'   None   '                                     

I think !s is preferable to !r, so I agree with your diff.

comment:4 Changed 5 years ago by jhpalmieri

  • Authors set to John Palmieri
  • Status changed from new to needs_review

Here's a patch. By the way, I used this format syntax as an experiment, because it's going to be the standard way of doing things in Python 3.

Changed 5 years ago by jhpalmieri

comment:5 Changed 5 years ago by slabbe

  • Dependencies set to #13131

comment:6 Changed 5 years ago by slabbe

  • Reviewers set to Sébastien Labbé
  • Status changed from needs_review to positive_review

All tests passed on sage/misc/table.py. Problem shown in the ticket is solved. Doc builds fine. Patch have a commit message. Positive review. (Tested using sage-5.8 with #13131.)

I believe the patchbot plugin failed blue icon issue is unrelated.

comment:7 Changed 5 years ago by jdemeyer

  • Merged in set to sage-5.10.beta5
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.