BUG: wrong detection if truncated repr is needed · Issue #22984 · pandas-dev/pandas (original) (raw)
There seems to be a bug in the detection of when a DataFrame repr will not fit the console width.
Small example, the repr of a 7 column float dataframe is 72 characters wide:
In [10]: pd.DataFrame(np.random.randn(3, 7))
Out[10]:
0 1 2 3 4 5 6
0 -0.039631 -0.630607 -0.041318 -0.679839 0.257494 -0.608414 0.013959
1 0.976692 0.578279 0.712098 1.292541 -0.934307 0.522638 -0.584541
2 -1.218953 0.124633 -0.705128 0.376275 0.044354 0.166730 1.122929
However, in my default terminal of 80 characters wide, it is truncated:
In [1]: pd.io.formats.console.get_terminal_size()
Out[1]: os.terminal_size(columns=80, lines=24)
In [2]: pd.DataFrame(np.random.randn(3, 7))
Out[2]:
0 1 2 ... 4 5 6
0 0.332255 0.408991 -0.446875 ... 0.533822 0.128198 0.421326
1 0.335729 -0.889485 2.038889 ... -0.263465 1.786649 1.190037
2 0.197376 1.742540 -1.259510 ... 0.643844 0.634065 -0.623578
[3 rows x 7 columns]
("funny" thing is that this truncated repr is actually exactly as wide as the non-truncated one ...)