-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Set pd.options.display.max_columns=0 by default #17023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
34999f0
31951f9
863112a
f44adce
2e85f48
8fda805
0e7bac8
b87cef1
e2e2714
e3abd9a
857f2ca
ed44504
dc64c52
cb2eb3e
3cf51ca
1eb3dad
d01c682
308be12
e77eb55
ab63657
f795914
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -658,6 +658,36 @@ Notice in the example above that the converted ``Categorical`` has retained ``or | |
|
||
Note that the unintenional conversion of ``ordered`` discussed above did not arise in previous versions due to separate bugs that prevented ``astype`` from doing any type of category to category conversion (:issue:`10696`, :issue:`18593`). These bugs have been fixed in this release, and motivated changing the default value of ``ordered``. | ||
|
||
+.. _whatsnew_0230.api_breaking.pretty_printing: | ||
|
||
Better pretty-printing of DataFrames in a terminal | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Previously, the default value for the maximum number of columns was | ||
``pd.options.display.max_columns=20``. This meant that relatively wide data | ||
frames would not fit within the terminal width, and pandas would introduce line | ||
breaks to display these 20 columns. This resulted in an output that was | ||
relatively difficult to read: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add this PR number here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you push the new change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed I forgot to push, the PR number is now a few lines below. |
||
|
||
.. image:: print_df_old.png | ||
|
||
If Python runs in a terminal, the maximum number of columns is now determined | ||
automatically so that the printed data frame fits within the current terminal | ||
width (``pd.options.display.max_columns=0``). If Python runs as a Jupyter | ||
kernel (such as the Jupyter QtConsole or a Jupyter notebook, as well as in many | ||
IDEs), this value cannot be inferred automatically and is thus set to `20` as | ||
in previos versions. In a terminal, this results in a much nicer output: | ||
|
||
.. image:: print_df_new.png | ||
|
||
Note that if you don't like the new default, you can always set this option | ||
yourself. To revert to the old setting, you can run this line: | ||
|
||
.. code-block:: python | ||
|
||
pd.options.display.max_columns = 20 | ||
|
||
.. _whatsnew_0230.api: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this one sneaked in due to merge conflict? (anyhow it can be removed) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, what do you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the diff, you added this line. But this should not be added (therefore I assumed you added it by accident while updating against master with rebasing/merging). But so you can just remove this line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean line 690 ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that's the line on which I commented. There is no header following for which that link would make sense (there is actually already another link label on line 692) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought there should be a section header before introducing the subsections. At least that's how it is done with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is correct. But I don't understand the relation with this line? This link is just floating with no section or subsection header following it. You already have a header with link at line 661 - 664 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's for the section below:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But that header already has the "whatsnew_0230.api.datetimelike" label, it does not need two labels. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, done. |
||
|
||
.. _whatsnew_0230.api.datetimelike: | ||
|
||
Datetimelike API Changes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
import sys | ||
import shutil | ||
|
||
__all__ = ['get_terminal_size'] | ||
__all__ = ['get_terminal_size', 'is_terminal'] | ||
|
||
|
||
def get_terminal_size(): | ||
|
@@ -48,6 +48,23 @@ def get_terminal_size(): | |
return tuple_xy | ||
|
||
|
||
def is_terminal(): | ||
""" | ||
Detect if Python is running in a terminal. | ||
|
||
Returns True if Python is running in a terminal or False if not. | ||
""" | ||
try: | ||
ip = get_ipython() | ||
except NameError: # assume standard Python interpreter in a terminal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don’t you need to import this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is available in IPython. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I.e. when you run IPython There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, this is ok then. |
||
return True | ||
else: | ||
if hasattr(ip, 'kernel'): # IPython as a Jupyter kernel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course... |
||
return False | ||
else: # IPython in a terminal | ||
return True | ||
|
||
|
||
def _get_terminal_size_windows(): | ||
res = None | ||
try: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a '+' here at the beginning of the line that should not be there