Closed bear24rw closed 7 years ago
this only matters if the terminal width cannot be detected, e.g. in a notebook.
What I'm saying is that when the terminal width can be detected why does it still wrap at 80?
no it shouldn't if u can show a case where it does use the with that would be a bug
Here is a simple example. Pandas correctly identifies the terminal as being 180 characters wide but still wraps at 80. Setting "display.width" to None fixes the issue and it wraps correctly.
In [24]: import pandas
In [25]: import seaborn
In [26]: pandas.__version__
Out[26]: u'0.17.0'
In [27]: pandas.util.terminal.get_terminal_size()
Out[27]: (180, 50)
In [28]: seaborn.load_dataset("titanic")
Out[28]:
survived pclass sex age sibsp parch fare embarked class \
0 0 3 male 22 1 0 7.2500 S Third
1 1 1 female 38 1 0 71.2833 C First
2 1 3 female 26 0 0 7.9250 S Third
3 1 1 female 35 1 0 53.1000 S First
4 0 3 male 35 0 0 8.0500 S Third
5 0 3 male NaN 0 0 8.4583 Q Third
6 0 1 male 54 0 0 51.8625 S First
7 0 3 male 2 3 1 21.0750 S Third
8 1 3 female 27 0 2 11.1333 S Third
9 1 2 female 14 1 0 30.0708 C Second
10 1 3 female 4 1 1 16.7000 S Third
11 1 1 female 58 0 0 26.5500 S First
12 0 3 male 20 0 0 8.0500 S Third
13 0 3 male 39 1 5 31.2750 S Third
14 0 3 female 14 0 0 7.8542 S Third
15 1 2 female 55 0 0 16.0000 S Second
16 0 3 male 2 4 1 29.1250 Q Third
17 1 2 male NaN 0 0 13.0000 S Second
18 0 3 female 31 1 0 18.0000 S Third
19 1 3 female NaN 0 0 7.2250 C Third
20 0 2 male 35 0 0 26.0000 S Second
21 1 2 male 34 0 0 13.0000 S Second
22 1 3 female 15 0 0 8.0292 Q Third
23 1 1 male 28 0 0 35.5000 S First
24 0 3 female 8 3 1 21.0750 S Third
25 1 3 female 38 1 5 31.3875 S Third
26 0 3 male NaN 0 0 7.2250 C Third
27 0 1 male 19 3 2 263.0000 S First
28 1 3 female NaN 0 0 7.8792 Q Third
29 0 3 male NaN 0 0 7.8958 S Third
.. ... ... ... ... ... ... ... ... ...
861 0 2 male 21 1 0 11.5000 S Second
862 1 1 female 48 0 0 25.9292 S First
863 0 3 female NaN 8 2 69.5500 S Third
864 0 2 male 24 0 0 13.0000 S Second
865 1 2 female 42 0 0 13.0000 S Second
866 1 2 female 27 1 0 13.8583 C Second
867 0 1 male 31 0 0 50.4958 S First
868 0 3 male NaN 0 0 9.5000 S Third
869 1 3 male 4 1 1 11.1333 S Third
870 0 3 male 26 0 0 7.8958 S Third
871 1 1 female 47 1 1 52.5542 S First
872 0 1 male 33 0 0 5.0000 S First
873 0 3 male 47 0 0 9.0000 S Third
874 1 2 female 28 1 0 24.0000 C Second
875 1 3 female 15 0 0 7.2250 C Third
876 0 3 male 20 0 0 9.8458 S Third
877 0 3 male 19 0 0 7.8958 S Third
878 0 3 male NaN 0 0 7.8958 S Third
879 1 1 female 56 0 1 83.1583 C First
880 1 2 female 25 0 1 26.0000 S Second
881 0 3 male 33 0 0 7.8958 S Third
882 0 3 female 22 0 0 10.5167 S Third
883 0 2 male 28 0 0 10.5000 S Second
884 0 3 male 25 0 0 7.0500 S Third
885 0 3 female 39 0 5 29.1250 Q Third
886 0 2 male 27 0 0 13.0000 S Second
887 1 1 female 19 0 0 30.0000 S First
888 0 3 female NaN 1 2 23.4500 S Third
889 1 1 male 26 0 0 30.0000 C First
890 0 3 male 32 0 0 7.7500 Q Third
who adult_male deck embark_town alive alone
0 man True NaN Southampton no False
1 woman False C Cherbourg yes False
2 woman False NaN Southampton yes True
3 woman False C Southampton yes False
4 man True NaN Southampton no True
5 man True NaN Queenstown no True
6 man True E Southampton no True
7 child False NaN Southampton no False
8 woman False NaN Southampton yes False
9 child False NaN Cherbourg yes False
10 child False G Southampton yes False
11 woman False C Southampton yes True
12 man True NaN Southampton no True
13 man True NaN Southampton no False
14 child False NaN Southampton no True
15 woman False NaN Southampton yes True
16 child False NaN Queenstown no False
17 man True NaN Southampton yes True
18 woman False NaN Southampton no False
19 woman False NaN Cherbourg yes True
20 man True NaN Southampton no True
21 man True D Southampton yes True
22 child False NaN Queenstown yes True
23 man True A Southampton yes True
24 child False NaN Southampton no False
25 woman False NaN Southampton yes False
26 man True NaN Cherbourg no True
27 man True C Southampton no False
28 woman False NaN Queenstown yes True
29 man True NaN Southampton no True
.. ... ... ... ... ... ...
861 man True NaN Southampton no False
862 woman False D Southampton yes True
863 woman False NaN Southampton no False
864 man True NaN Southampton no True
865 woman False NaN Southampton yes True
866 woman False NaN Cherbourg yes False
867 man True A Southampton no True
868 man True NaN Southampton no True
869 child False NaN Southampton yes False
870 man True NaN Southampton no True
871 woman False D Southampton yes False
872 man True B Southampton no True
873 man True NaN Southampton no True
874 woman False NaN Cherbourg yes False
875 child False NaN Cherbourg yes True
876 man True NaN Southampton no True
877 man True NaN Southampton no True
878 man True NaN Southampton no True
879 woman False C Cherbourg yes False
880 woman False NaN Southampton yes False
881 man True NaN Southampton no True
882 woman False NaN Southampton no True
883 man True NaN Southampton no True
884 man True NaN Southampton no True
885 woman False NaN Queenstown no False
886 man True NaN Southampton no True
887 woman False B Southampton yes True
888 woman False NaN Southampton no False
889 man True C Cherbourg yes True
890 man True NaN Queenstown no True
[891 rows x 15 columns]
In [29]: pandas.set_option('display.width', None)
In [30]: seaborn.load_dataset("titanic")
Out[30]:
survived pclass sex age sibsp parch fare embarked class who adult_male deck embark_town alive alone
0 0 3 male 22 1 0 7.2500 S Third man True NaN Southampton no False
1 1 1 female 38 1 0 71.2833 C First woman False C Cherbourg yes False
2 1 3 female 26 0 0 7.9250 S Third woman False NaN Southampton yes True
3 1 1 female 35 1 0 53.1000 S First woman False C Southampton yes False
4 0 3 male 35 0 0 8.0500 S Third man True NaN Southampton no True
5 0 3 male NaN 0 0 8.4583 Q Third man True NaN Queenstown no True
6 0 1 male 54 0 0 51.8625 S First man True E Southampton no True
7 0 3 male 2 3 1 21.0750 S Third child False NaN Southampton no False
8 1 3 female 27 0 2 11.1333 S Third woman False NaN Southampton yes False
9 1 2 female 14 1 0 30.0708 C Second child False NaN Cherbourg yes False
10 1 3 female 4 1 1 16.7000 S Third child False G Southampton yes False
11 1 1 female 58 0 0 26.5500 S First woman False C Southampton yes True
12 0 3 male 20 0 0 8.0500 S Third man True NaN Southampton no True
13 0 3 male 39 1 5 31.2750 S Third man True NaN Southampton no False
14 0 3 female 14 0 0 7.8542 S Third child False NaN Southampton no True
15 1 2 female 55 0 0 16.0000 S Second woman False NaN Southampton yes True
16 0 3 male 2 4 1 29.1250 Q Third child False NaN Queenstown no False
17 1 2 male NaN 0 0 13.0000 S Second man True NaN Southampton yes True
18 0 3 female 31 1 0 18.0000 S Third woman False NaN Southampton no False
19 1 3 female NaN 0 0 7.2250 C Third woman False NaN Cherbourg yes True
20 0 2 male 35 0 0 26.0000 S Second man True NaN Southampton no True
21 1 2 male 34 0 0 13.0000 S Second man True D Southampton yes True
22 1 3 female 15 0 0 8.0292 Q Third child False NaN Queenstown yes True
23 1 1 male 28 0 0 35.5000 S First man True A Southampton yes True
24 0 3 female 8 3 1 21.0750 S Third child False NaN Southampton no False
25 1 3 female 38 1 5 31.3875 S Third woman False NaN Southampton yes False
26 0 3 male NaN 0 0 7.2250 C Third man True NaN Cherbourg no True
27 0 1 male 19 3 2 263.0000 S First man True C Southampton no False
28 1 3 female NaN 0 0 7.8792 Q Third woman False NaN Queenstown yes True
29 0 3 male NaN 0 0 7.8958 S Third man True NaN Southampton no True
.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
861 0 2 male 21 1 0 11.5000 S Second man True NaN Southampton no False
862 1 1 female 48 0 0 25.9292 S First woman False D Southampton yes True
863 0 3 female NaN 8 2 69.5500 S Third woman False NaN Southampton no False
864 0 2 male 24 0 0 13.0000 S Second man True NaN Southampton no True
865 1 2 female 42 0 0 13.0000 S Second woman False NaN Southampton yes True
866 1 2 female 27 1 0 13.8583 C Second woman False NaN Cherbourg yes False
867 0 1 male 31 0 0 50.4958 S First man True A Southampton no True
868 0 3 male NaN 0 0 9.5000 S Third man True NaN Southampton no True
869 1 3 male 4 1 1 11.1333 S Third child False NaN Southampton yes False
870 0 3 male 26 0 0 7.8958 S Third man True NaN Southampton no True
871 1 1 female 47 1 1 52.5542 S First woman False D Southampton yes False
872 0 1 male 33 0 0 5.0000 S First man True B Southampton no True
873 0 3 male 47 0 0 9.0000 S Third man True NaN Southampton no True
874 1 2 female 28 1 0 24.0000 C Second woman False NaN Cherbourg yes False
875 1 3 female 15 0 0 7.2250 C Third child False NaN Cherbourg yes True
876 0 3 male 20 0 0 9.8458 S Third man True NaN Southampton no True
877 0 3 male 19 0 0 7.8958 S Third man True NaN Southampton no True
878 0 3 male NaN 0 0 7.8958 S Third man True NaN Southampton no True
879 1 1 female 56 0 1 83.1583 C First woman False C Cherbourg yes False
880 1 2 female 25 0 1 26.0000 S Second woman False NaN Southampton yes False
881 0 3 male 33 0 0 7.8958 S Third man True NaN Southampton no True
882 0 3 female 22 0 0 10.5167 S Third woman False NaN Southampton no True
883 0 2 male 28 0 0 10.5000 S Second man True NaN Southampton no True
884 0 3 male 25 0 0 7.0500 S Third man True NaN Southampton no True
885 0 3 female 39 0 5 29.1250 Q Third woman False NaN Queenstown no False
886 0 2 male 27 0 0 13.0000 S Second man True NaN Southampton no True
887 1 1 female 19 0 0 30.0000 S First woman False B Southampton yes True
888 0 3 female NaN 1 2 23.4500 S Third woman False NaN Southampton no False
889 1 1 male 26 0 0 30.0000 C First man True C Cherbourg yes True
890 0 3 male 32 0 0 7.7500 Q Third man True NaN Queenstown no True
[891 rows x 15 columns]
not sure this proves anything, their are a myriad of options that affect this kind of printing, e.g. display.max_columns
being one of them. you would have to step thru the code and see exactly the case you are talking about.
Use a generically construction frame and context managers to diagnose, e.g.:
In [42]: df = DataFrame(np.random.randn(5,30))
In [46]: with pd.option_context('display.width',50,'display.max_columns',999):
print(df)
The problem is the get_console_size()
function of format.py
I see now that it is by design to always use display.width
unless it is None
. I don't agree with this default. When I'm in the terminal I always want it to use all the available width. It seems the only reason it doesn't do that right now is because the ipython frontend doesn't report a real width. Terminals should default to using the actual width of the terminal and the ipython frontend should default to some fixed value.
@jreback Reading the documentation:
Width of the display in characters. In case python/IPython is running in a terminal this can be set to None and pandas will correctly auto-detect the width. Note that the IPython notebook, IPython qtconsole, or IDLE do not run in a terminal and hence it is not possible to correctly detect the width.
it seems to me this is on purpose not None, and if you want autodetection of the width, you have to manually set it to None
there is quite a lot of discussion on this in the past. so would like someone to go thru issues and see what the arguments are for/against this.
@jreback, If ipython notebook qtconsole, IDLE, et al really cannot correctly detect their width, that is a problem with those implementations. Breaking the default configuration for shell users does not fix the underlying issue.
$ git blame ./core/config_init.py a4a71f89 (Viktor Kerkez 3 years ago 323) cf.register_option('width', 80, pc_width_doc,
$ git blame ./core/config.py | grep width 8721059d (y-p 3 years, 11 months ago 655) def pp_options_list(keys, width=80, _print=False)
Has this really been broken for 3 years?
@drewm1980 not really sure this is broken, rather its a user preference. I simply set the width to what I want then it just works. If you don't have a terminal width returned then it defaults to 80. The issue is that you want the default to change, but it already works that way if the terminal is indeed returned correctly.
@jreback I know its been months but would it still be worthwhile to make a PR for this? If not its probably a good idea to close this for good.
with has been removed in favor of max_columns
i think there is an open or about this actually
PR
@jreback yeah it seems like this https://github.com/pandas-dev/pandas/pull/17023 covers it. In that case this issue can probably be closed for good.
What is the reasoning for defaulting "display.width" to 80? Pandas knows the width of the terminal so why not default "display.width" to 'None' and let Pandas wrap to the terminal width by default?