From 26e5e30f97a11561ca72c767a7b54ee8f6805fa0 Mon Sep 17 00:00:00 2001 From: y-p Date: Mon, 20 May 2013 18:48:18 +0300 Subject: [PATCH 1/4] ENH/CLN: add helpers for ipnb detection --- pandas/core/common.py | 17 ++++++++++++++++- pandas/core/format.py | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pandas/core/common.py b/pandas/core/common.py index a52c932b30ba4..cbc85e6b91c33 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -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 """ diff --git a/pandas/core/format.py b/pandas/core/format.py index 3d38caa84492f..608165f4ed340 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -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 From 92194336fd63f153beeaaa72ad4e71e1c6d590b0 Mon Sep 17 00:00:00 2001 From: y-p Date: Mon, 20 May 2013 19:25:08 +0300 Subject: [PATCH 2/4] ENH: special case HTML repr behaviour on ipnb GH3573 PTF --- pandas/core/frame.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ed56a658d817d..43a54ae987241 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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: @@ -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): """ @@ -731,12 +743,16 @@ 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') 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 ('
Date: Tue, 21 May 2013 02:47:22 +0300 Subject: [PATCH 4/4] DOC: update RELEASE.rst --- RELEASE.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/RELEASE.rst b/RELEASE.rst index e02ad66252bdc..c2d4154bf2587 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -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_) @@ -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`` @@ -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_)