Skip to content

ENH: special case HTML repr behaviour on ipnb GH3573 #3657

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

Merged
merged 4 commits into from May 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pandas 0.11.1
list of the rows from which to read the index. Added the option,
``tupleize_cols`` to provide compatiblity for the pre 0.11.1 behavior of
writing and reading multi-index columns via a list of tuples. The default in
0.11.1 is to write lists of tuples and *not* interpret list of tuples as a
multi-index column.
0.11.1 is to write lists of tuples and *not* interpret list of tuples as a
multi-index column.
Note: The default value will change in 0.12 to make the default *to* write and
read multi-index columns in the new format. (GH3571_, GH1651_, GH3141_)
- Add iterator to ``Series.str`` (GH3638_)
Expand Down Expand Up @@ -79,8 +79,8 @@ pandas 0.11.1
``timedelta64[ns]`` to ``object/int`` (GH3425_)
- Do not allow datetimelike/timedeltalike creation except with valid types
(e.g. cannot pass ``datetime64[ms]``) (GH3423_)
- Add ``squeeze`` keyword to ``groupby`` to allow reduction from
DataFrame -> Series if groups are unique. Regression from 0.10.1,
- Add ``squeeze`` keyword to ``groupby`` to allow reduction from
DataFrame -> Series if groups are unique. Regression from 0.10.1,
partial revert on (GH2893_) with (GH3596_)
- Raise on ``iloc`` when boolean indexing with a label based indexer mask
e.g. a boolean Series, even with integer labels, will raise. Since ``iloc``
Expand Down Expand Up @@ -134,11 +134,12 @@ pandas 0.11.1
is a ``list`` or ``tuple``.
- Fixed bug where a time-series was being selected in preference to an actual column name
in a frame (GH3594_)
- Fix modulo and integer division on Series,DataFrames to act similary to ``float`` dtypes to return
- Fix modulo and integer division on Series,DataFrames to act similary to ``float`` dtypes to return
``np.nan`` or ``np.inf`` as appropriate (GH3590_)
- Fix incorrect dtype on groupby with ``as_index=False`` (GH3610_)
- Fix ``read_csv`` to correctly encode identical na_values, e.g. ``na_values=[-999.0,-999]``
was failing (GH3611_)
- Disable HTML output in qtconsole again. (GH3657_)
- Fix indexing issue in ndim >= 3 with ``iloc`` (GH3617_)
- Correctly parse date columns with embedded (nan/NaT) into datetime64[ns] dtype in ``read_csv``
when ``parse_dates`` is specified (GH3062_)
Expand Down
17 changes: 16 additions & 1 deletion pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,8 +1904,23 @@ def in_qtconsole():
return True
except:
return False
return False

def in_ipnb():
"""
check if we're inside an IPython Notebook
"""
try:
ip = get_ipython()
front_end = (ip.config.get('KernelApp',{}).get('parent_appname',"") or
ip.config.get('IPKernelApp',{}).get('parent_appname',""))
if 'notebook' in front_end.lower():
return True
except:
return False
return False

def in_ipnb_frontend():
def in_ipython_frontend():
"""
check if we're inside an an IPython zmq frontend
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ def get_console_size():
# Simple. yeah.

if com.in_interactive_session():
if com.in_ipnb_frontend():
if com.in_ipython_frontend():
# sane defaults for interactive non-shell terminal
# match default for width,height in config_init
from pandas.core.config import get_default_val
Expand Down
30 changes: 26 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,19 +621,26 @@ def _repr_fits_vertical_(self):
max_rows = max_rows or height +1
return len(self) <= min(max_rows, height)

def _repr_fits_horizontal_(self):
def _repr_fits_horizontal_(self,ignore_width=False):
"""
Check if full repr fits in horizontal boundaries imposed by the display
options width and max_columns. In case off non-interactive session, no
boundaries apply.

ignore_width is here so ipnb+HTML output can behave the way
users expect. display.max_columns remains in effect.
GH3541, GH3573
"""

# everytime you add an if-clause here, god slaughters a kitten.
# please. think of the kittens.
width, height = fmt.get_console_size()
max_columns = get_option("display.max_columns")
nb_columns = len(self.columns)

# exceed max columns
if ((max_columns and nb_columns > max_columns) or
(width and nb_columns > (width // 2))):
((not ignore_width) and width and nb_columns > (width // 2))):
return False

if width is None:
Expand All @@ -655,7 +662,12 @@ def _repr_fits_horizontal_(self):
d.to_string(buf=buf)
value = buf.getvalue()
repr_width = max([len(l) for l in value.split('\n')])
return repr_width <= width

# special case ipnb+HTML repr
if not ignore_width:
return repr_width <= width
else:
return True

def __str__(self):
"""
Expand Down Expand Up @@ -731,12 +743,22 @@ def _repr_html_(self):
Return a html representation for a particular DataFrame.
Mainly for IPython notebook.
"""
# ipnb in html repr mode allows scrolling
# users strongly prefer to h-scroll a wide HTML table in the browser
# then to get a summary view. GH3541, GH3573
ipnbh = com.in_ipnb() and get_option('display.notebook_repr_html')

# qtconsole doesn't report it's line width, and also
# behaves badly when outputting an HTML table
# that doesn't fit the window, so disable it.
if com.in_qtconsole():
raise ValueError('Disable HTML output in QtConsole')

if get_option("display.notebook_repr_html"):
fits_vertical = self._repr_fits_vertical_()
fits_horizontal = False
if fits_vertical:
fits_horizontal = self._repr_fits_horizontal_()
fits_horizontal = self._repr_fits_horizontal_(ignore_width=ipnbh)

if fits_horizontal and fits_vertical:
return ('<div style="max-height:1000px;'
Expand Down