You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SEPARATING_LINE doesn't work with tablefmt='orgtbl'. #250
SEPARATING_LINE is borked at least with 'html', 'simple_outline' and 'latex' formats. It is printed literally, as a single-character string '\001', exactly as it's defined in source:
# Constant that can be used as part of passed rows to generate a separating line
# It is purposely an unprintable character, very unlikely to be used in a table
SEPARATING_LINE="\001"
The HTML format is messed up even worse: the generated table/tr/td tree structure is malformed.
My general impression is that many "more complex" that plain character formats are broken, although I do not know how the difference in their internal handling, neither did I test many of them.
Interactive from IPython console in Jupyter:
# Jupyter setting to print all non-`None` evaluation results, not only the last one in a cell:%configZMQInteractiveShell.ast_node_interactivity='all'fromtabulateimporttabulate, SEPARATING_LINE, __version__astabver
('tabulate version:', tabver); deltabverdata= [("m1", 0.9), ("m2", 0.999), SEPARATING_LINE, ("acc", 92.24), ("loss", 0.2121)]
print(tabulate(data)) # The default default works.
@astanin, tangentially, there exist a clear pattern, widely used in Python, Java, .NET and other assign-by-reference languages all alike, which I can't help suggesting to imbue the token SEPARATING_LINE with a unique identity, thus avoiding the reliance on the fact that a specific string is “very unlikely to be used” in a table. The main idea is that Python's object type has no extrinsic "value" that can be sensibly compared to the same of another object instance. The only property than an instance of object has is being an instance of object; its only equatable property is its intrinsic identity. Two object instances are always compared by reference: one can only tell if two references point to the same instance or two different ones. IMO, an implementation not relying on the table's content might have been simply
SEPARATING_LINE=object()
Since Python assigns variables by reference, assigning SEPARATING_LINE to a variable, binding it to a function argument, or using in a data structure, as it's supposed to be used, will always refer to the same instance, and there is nothing comparable in this type except the instance's identity. This is easier to show with an example than tell:
(I'm trimming middle digits of the unique instance ids, as they are 15 decimal places integers 8-O):
False
(True, False)
[13…648, 13…648, 13…664]
Python, unlike .NET or Java, doesn't distinguish between objects and values (value types are for things that cannot live in the garbage-collected heap, but can e.g. on the stack, or as part of other values/object, like class data fields); everything in Python is an object. This is one of the reasons why it has such a dismal performance and resists all attempts at [pre-]compilation or optimization fiercely. If I weren't aware of its history, I'd assume that one of its main design goals had been to make it as inefficient as possible, however hard an implementer would be trying to. (The secondary goal would be to make it a write-only language, as unreadable as only possible; yet another to create a language that would be even more boring to write than Fortran; all three have been achieved with flying colors). In fact, as we all know, there were simply no overarching design goals at all. :-) Still, this surprised me, when I decided to verify that I'm not making a wrong suggestion, including memory use—although by a singleton instance, unimportant at all; but still, I was in the check-it-all mode, to avoid unintentionally confusing you, had it even been in the slightest:
an integer a string an object()
---------------- ------------- ------------- ----------------
type(¤) <class 'int'> <class 'str'> <class 'object'>
¤.__sizeof__() 28 50 16
sys.getsizeof(¤) 28 50 16
Generally, sys.getsizeof(x) >= ¤.__sizeof__(), but they seem always equal in this Python. But how come the type int is 12 bytes larger than its parent class object, I have not even a remote idea. Coming from the C++ land, I'm hardly used to seeing 12-byte integers... Python is an enigmatic language indeed. :-)
Activity
kkm000 commentedon Mar 21, 2023
SEPARATING_LINEis borked at least with'html','simple_outline'and'latex'formats. It is printed literally, as a single-character string'\001', exactly as it's defined in source:python-tabulate/tabulate/__init__.py
Lines 48 to 50 in 83fd4fb
The HTML format is messed up even worse: the generated
table/tr/tdtree structure is malformed.My general impression is that many "more complex" that plain character formats are broken, although I do not know how the difference in their internal handling, neither did I test many of them.
Interactive from IPython console in Jupyter:
tablefmt='simple_outline'just outputs"\001"for theSEPARATING_LINE(@gety9, this is a repro of your report):As does
tablefmt='latex':(I've compressed whitespace runs to a single space each in the second, representation form output; it's on the longish side)
tablefmt='html'closes table atSEPARATING_LINE, but then continues with a<td>etc. on the next row:I'm splitting the
repr(...)output string below into multiple lines for readability. Actual output is a ≈700-char-long, unbroken line:Obligatory system and pertinent software versions:
@astanin, tangentially, there exist a clear pattern, widely used in Python, Java, .NET and other assign-by-reference languages all alike, which I can't help suggesting to imbue the token
SEPARATING_LINEwith a unique identity, thus avoiding the reliance on the fact that a specific string is “very unlikely to be used” in a table. The main idea is that Python'sobjecttype has no extrinsic "value" that can be sensibly compared to the same of anotherobjectinstance. The only property than an instance ofobjecthas is being an instance ofobject; its only equatable property is its intrinsic identity. Twoobjectinstances are always compared by reference: one can only tell if two references point to the same instance or two different ones. IMO, an implementation not relying on the table's content might have been simplySince Python assigns variables by reference, assigning
SEPARATING_LINEto a variable, binding it to a function argument, or using in a data structure, as it's supposed to be used, will always refer to the same instance, and there is nothing comparable in this type except the instance's identity. This is easier to show with an example than tell:(I'm trimming middle digits of the unique instance
ids, as they are 15 decimal places integers 8-O):Python, unlike .NET or Java, doesn't distinguish between objects and values (value types are for things that cannot live in the garbage-collected heap, but can e.g. on the stack, or as part of other values/object, like class data fields); everything in Python is an object. This is one of the reasons why it has such a dismal performance and resists all attempts at [pre-]compilation or optimization fiercely. If I weren't aware of its history, I'd assume that one of its main design goals had been to make it as inefficient as possible, however hard an implementer would be trying to. (The secondary goal would be to make it a write-only language, as unreadable as only possible; yet another to create a language that would be even more boring to write than Fortran; all three have been achieved with flying colors). In fact, as we all know, there were simply no overarching design goals at all. :-) Still, this surprised me, when I decided to verify that I'm not making a wrong suggestion, including memory use—although by a singleton instance, unimportant at all; but still, I was in the check-it-all mode, to avoid unintentionally confusing you, had it even been in the slightest:
Generally,
sys.getsizeof(x) >= ¤.__sizeof__(), but they seem always equal in this Python. But how come the typeintis 12 bytes larger than its parent classobject, I have not even a remote idea. Coming from the C++ land, I'm hardly used to seeing 12-byte integers... Python is an enigmatic language indeed. :-)martinhansdk commentedon Apr 14, 2023
The
githubformat is broken as well.