Skip to content

Commit 84fb0e0

Browse files
committed
Merge PR #3663
2 parents 2bd1cf8 + 0c0180f commit 84fb0e0

File tree

7 files changed

+111
-65
lines changed

7 files changed

+111
-65
lines changed

RELEASE.rst

+11-6
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pandas 0.11.1
4040
list of the rows from which to read the index. Added the option,
4141
``tupleize_cols`` to provide compatiblity for the pre 0.11.1 behavior of
4242
writing and reading multi-index columns via a list of tuples. The default in
43-
0.11.1 is to write lists of tuples and *not* interpret list of tuples as a
44-
multi-index column.
43+
0.11.1 is to write lists of tuples and *not* interpret list of tuples as a
44+
multi-index column.
4545
Note: The default value will change in 0.12 to make the default *to* write and
4646
read multi-index columns in the new format. (GH3571_, GH1651_, GH3141_)
4747
- Add iterator to ``Series.str`` (GH3638_)
@@ -63,14 +63,15 @@ pandas 0.11.1
6363
- Add modulo operator to Series, DataFrame
6464
- Add ``date`` method to DatetimeIndex
6565
- Simplified the API and added a describe method to Categorical
66-
- ``melt`` now accepts the optional parameters ``var_name`` and ``value_name``
66+
- ``melt`` now accepts the optional parameters ``var_name`` and ``value_name``
6767
to specify custom column names of the returned DataFrame (GH3649_),
6868
thanks @hoechenberger
6969
- ``read_html`` no longer performs hard date conversion
7070
- Plotting functions now raise a ``TypeError`` before trying to plot anything
7171
if the associated objects have have a dtype of ``object`` (GH1818_,
7272
GH3572_). This happens before any drawing takes place which elimnates any
7373
spurious plots from showing up.
74+
- Added Faq section on repr display options, to help users customize their setup.
7475

7576
**API Changes**
7677

@@ -87,8 +88,8 @@ pandas 0.11.1
8788
``timedelta64[ns]`` to ``object/int`` (GH3425_)
8889
- Do not allow datetimelike/timedeltalike creation except with valid types
8990
(e.g. cannot pass ``datetime64[ms]``) (GH3423_)
90-
- Add ``squeeze`` keyword to ``groupby`` to allow reduction from
91-
DataFrame -> Series if groups are unique. Regression from 0.10.1,
91+
- Add ``squeeze`` keyword to ``groupby`` to allow reduction from
92+
DataFrame -> Series if groups are unique. Regression from 0.10.1,
9293
partial revert on (GH2893_) with (GH3596_)
9394
- Raise on ``iloc`` when boolean indexing with a label based indexer mask
9495
e.g. a boolean Series, even with integer labels, will raise. Since ``iloc``
@@ -99,6 +100,8 @@ pandas 0.11.1
99100
- ``DataFrame.interpolate()`` is now deprecated. Please use
100101
``DataFrame.fillna()`` and ``DataFrame.replace()`` instead (GH3582_,
101102
GH3675_, GH3676_).
103+
- Deprecated display.height, display.width is now only a formatting option
104+
does not control triggering of summary, similar to < 0.11.0.
102105

103106
**Bug Fixes**
104107

@@ -148,11 +151,13 @@ pandas 0.11.1
148151
is a ``list`` or ``tuple``.
149152
- Fixed bug where a time-series was being selected in preference to an actual column name
150153
in a frame (GH3594_)
151-
- Fix modulo and integer division on Series,DataFrames to act similary to ``float`` dtypes to return
154+
- Fix modulo and integer division on Series,DataFrames to act similary to ``float`` dtypes to return
152155
``np.nan`` or ``np.inf`` as appropriate (GH3590_)
153156
- Fix incorrect dtype on groupby with ``as_index=False`` (GH3610_)
154157
- Fix ``read_csv`` to correctly encode identical na_values, e.g. ``na_values=[-999.0,-999]``
155158
was failing (GH3611_)
159+
- Disable HTML output in qtconsole again. (GH3657_)
160+
- Reworked the new repr display logic, which users found confusing. (GH3663_)
156161
- Fix indexing issue in ndim >= 3 with ``iloc`` (GH3617_)
157162
- Correctly parse date columns with embedded (nan/NaT) into datetime64[ns] dtype in ``read_csv``
158163
when ``parse_dates`` is specified (GH3062_)

doc/source/faq.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ horizontal scrolling, auto-detection of width/height.
3535
To appropriately address all these environments, the display behavior is controlled
3636
by several options, which you're encouraged to tweak to suit your setup.
3737

38-
As of 0.11.0, the relavent options are all under the `display` namespace,
39-
(e.g. display.width, display.height, etc'):
38+
As of 0.11.1, these are the relavent options, all under the `display` namespace,
39+
(e.g. display.width, etc'):
4040
- notebook_repr_html: if True, IPython frontends with HTML support will display
4141
dataframes as HTML tables when possible.
4242
- expand_repr (default True): when the frame width cannot fit within the screen,
@@ -45,10 +45,10 @@ As of 0.11.0, the relavent options are all under the `display` namespace,
4545
- max_columns: max dataframe columns to display. a wider frame will trigger
4646
a summary view, unless `expand_repr` is True and HTML output is disabled.
4747
- max_rows: max dataframe rows display. a longer frame will trigger a summary view.
48-
- width: width of display screen in characters. When using a terminal, setting this to None
49-
will trigger auto-detection of terminal width.
50-
- height: height of display screen. When using a terminal, setting this to None
51-
will trigger auto-detection of terminal height.
48+
- width: width of display screen in characters, used to determine the width of lines
49+
when expand_repr is active, Setting this to None will trigger auto-detection of terminal
50+
width, this only works for proper terminals, not IPython frontends such as ipnb.
51+
width is ignored in IPython notebook, since the browser provides horizontal scrolling.
5252

5353
IPython users can use the IPython startup file to import pandas and set these
5454
options automatically when starting up.

pandas/core/common.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1907,8 +1907,23 @@ def in_qtconsole():
19071907
return True
19081908
except:
19091909
return False
1910+
return False
1911+
1912+
def in_ipnb():
1913+
"""
1914+
check if we're inside an IPython Notebook
1915+
"""
1916+
try:
1917+
ip = get_ipython()
1918+
front_end = (ip.config.get('KernelApp',{}).get('parent_appname',"") or
1919+
ip.config.get('IPKernelApp',{}).get('parent_appname',""))
1920+
if 'notebook' in front_end.lower():
1921+
return True
1922+
except:
1923+
return False
1924+
return False
19101925

1911-
def in_ipnb_frontend():
1926+
def in_ipython_frontend():
19121927
"""
19131928
check if we're inside an an IPython zmq frontend
19141929
"""

pandas/core/config_init.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@
120120

121121
pc_line_width_doc = """
122122
: int
123-
When printing wide DataFrames, this is the width of each line.
123+
Deprecated.
124124
"""
125125

126126
pc_line_width_deprecation_warning = """\
127127
line_width has been deprecated, use display.width instead (currently both are identical)
128128
"""
129129

130+
pc_height_deprecation_warning = """\
131+
height has been deprecated.
132+
"""
133+
130134
pc_width_doc = """
131135
: int
132136
Width of the display in characters. In case python/IPython is running in
@@ -138,10 +142,7 @@
138142

139143
pc_height_doc = """
140144
: int
141-
Height of the display in lines. In case python/IPython is running in a
142-
terminal this can be set to None and pandas will auto-detect the width.
143-
Note that the IPython notebook, IPython qtconsole, or IDLE do not run
144-
in a terminal, and hence it is not possible to correctly detect the height.
145+
Deprecated.
145146
"""
146147

147148
pc_chop_threshold_doc = """
@@ -244,10 +245,15 @@ def mpl_style_cb(key):
244245
validator=is_instance_factory([type(None), int]))
245246
# redirected to width, make defval identical
246247
cf.register_option('line_width', get_default_val('display.width'), pc_line_width_doc)
248+
247249
cf.deprecate_option('display.line_width',
248250
msg=pc_line_width_deprecation_warning,
249251
rkey='display.width')
250252

253+
cf.deprecate_option('display.height',
254+
msg=pc_height_deprecation_warning,
255+
rkey='display.height')
256+
251257
tc_sim_interactive_doc = """
252258
: boolean
253259
Whether to simulate interactive mode for purposes of testing

pandas/core/format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ def detect_console_encoding():
17021702
def get_console_size():
17031703
"""Return console size as tuple = (width, height).
17041704
1705-
May return (None,None) in some cases.
1705+
Returns (None,None) in non-interactive session.
17061706
"""
17071707
display_width = get_option('display.width')
17081708
display_height = get_option('display.height')
@@ -1718,7 +1718,7 @@ def get_console_size():
17181718
# Simple. yeah.
17191719

17201720
if com.in_interactive_session():
1721-
if com.in_ipnb_frontend():
1721+
if com.in_ipython_frontend():
17221722
# sane defaults for interactive non-shell terminal
17231723
# match default for width,height in config_init
17241724
from pandas.core.config import get_default_val

pandas/core/frame.py

+45-33
Original file line numberDiff line numberDiff line change
@@ -605,57 +605,62 @@ def __nonzero__(self):
605605

606606
def _repr_fits_vertical_(self):
607607
"""
608-
Check if full repr fits in vertical boundaries imposed by the display
609-
options height and max_rows. In case of non-interactive session,
610-
no boundaries apply.
608+
Check length against max_rows.
611609
"""
612-
width, height = fmt.get_console_size()
613610
max_rows = get_option("display.max_rows")
611+
return len(self) <= max_rows
614612

615-
if height is None and max_rows is None:
616-
return True
617-
618-
else:
619-
# min of two, where one may be None
620-
height = height or max_rows +1
621-
max_rows = max_rows or height +1
622-
return len(self) <= min(max_rows, height)
623-
624-
def _repr_fits_horizontal_(self):
613+
def _repr_fits_horizontal_(self,ignore_width=False):
625614
"""
626615
Check if full repr fits in horizontal boundaries imposed by the display
627616
options width and max_columns. In case off non-interactive session, no
628617
boundaries apply.
618+
619+
ignore_width is here so ipnb+HTML output can behave the way
620+
users expect. display.max_columns remains in effect.
621+
GH3541, GH3573
629622
"""
623+
630624
width, height = fmt.get_console_size()
631625
max_columns = get_option("display.max_columns")
632626
nb_columns = len(self.columns)
633627

634628
# exceed max columns
635629
if ((max_columns and nb_columns > max_columns) or
636-
(width and nb_columns > (width // 2))):
630+
((not ignore_width) and width and nb_columns > (width // 2))):
637631
return False
638632

639-
if width is None:
640-
# no sense finding width of repr if no width set
633+
if (ignore_width # used by repr_html under IPython notebook
634+
or not com.in_interactive_session()): # scripts ignore terminal dims
641635
return True
642636

637+
if (get_option('display.width') is not None or
638+
com.in_ipython_frontend()):
639+
# check at least the column row for excessive width
640+
max_rows = 1
641+
else:
642+
max_rows = get_option("display.max_rows")
643+
644+
# when auto-detecting, so width=None and not in ipython front end
645+
# check whether repr fits horizontal by actualy checking
646+
# the width of the rendered repr
643647
buf = StringIO()
644648

645649
# only care about the stuff we'll actually print out
646650
# and to_string on entire frame may be expensive
647651
d = self
648-
max_rows = get_option("display.max_rows")
649-
if not (height is None and max_rows is None):
652+
653+
if not (max_rows is None): # unlimited rows
650654
# min of two, where one may be None
651-
height = height or max_rows +1
652-
max_rows = max_rows or height +1
653-
d=d.iloc[:min(max_rows, height,len(d))]
655+
d=d.iloc[:min(max_rows,len(d))]
656+
else:
657+
return True
654658

655659
d.to_string(buf=buf)
656660
value = buf.getvalue()
657661
repr_width = max([len(l) for l in value.split('\n')])
658-
return repr_width <= width
662+
663+
return repr_width < width
659664

660665
def __str__(self):
661666
"""
@@ -697,14 +702,11 @@ def __unicode__(self):
697702
if fits_vertical and fits_horizontal:
698703
self.to_string(buf=buf)
699704
else:
700-
width, height = fmt.get_console_size()
701-
max_rows = get_option("display.max_rows") or height
702-
# expand_repr basically takes the extrac columns that don't
703-
# fit the width, and creates a new page, which increases
704-
# the effective row count. check number of cols agaibst
705-
# max rows to catch wrapping. that would exceed max_rows.
706-
if (get_option("display.expand_frame_repr") and fits_vertical and
707-
len(self.columns) < max_rows):
705+
width, _ = fmt.get_console_size()
706+
max_rows = get_option("display.max_rows")
707+
if (get_option("display.expand_frame_repr")
708+
and fits_vertical):
709+
# and len(self.columns) < max_rows)
708710
self.to_string(buf=buf, line_width=width)
709711
else:
710712
max_info_rows = get_option('display.max_info_rows')
@@ -731,12 +733,22 @@ def _repr_html_(self):
731733
Return a html representation for a particular DataFrame.
732734
Mainly for IPython notebook.
733735
"""
736+
# ipnb in html repr mode allows scrolling
737+
# users strongly prefer to h-scroll a wide HTML table in the browser
738+
# then to get a summary view. GH3541, GH3573
739+
ipnbh = com.in_ipnb() and get_option('display.notebook_repr_html')
740+
741+
# qtconsole doesn't report it's line width, and also
742+
# behaves badly when outputting an HTML table
743+
# that doesn't fit the window, so disable it.
744+
if com.in_qtconsole():
745+
raise ValueError('Disable HTML output in QtConsole')
734746

735747
if get_option("display.notebook_repr_html"):
736748
fits_vertical = self._repr_fits_vertical_()
737749
fits_horizontal = False
738750
if fits_vertical:
739-
fits_horizontal = self._repr_fits_horizontal_()
751+
fits_horizontal = self._repr_fits_horizontal_(ignore_width=ipnbh)
740752

741753
if fits_horizontal and fits_vertical:
742754
return ('<div style="max-height:1000px;'
@@ -870,7 +882,7 @@ def __contains__(self, key):
870882

871883
# Python 2 division methods
872884
if not py3compat.PY3:
873-
__div__ = _arith_method(operator.div, '__div__', '/',
885+
__div__ = _arith_method(operator.div, '__div__', '/',
874886
default_axis=None, fill_zeros=np.inf)
875887
__rdiv__ = _arith_method(lambda x, y: y / x, '__rdiv__',
876888
default_axis=None, fill_zeros=np.inf)

0 commit comments

Comments
 (0)