From cb803568fd62f7a80fa44001fc2c24a2b62fa87e Mon Sep 17 00:00:00 2001 From: Soren Date: Sat, 5 May 2018 16:52:29 -0600 Subject: [PATCH 01/16] Added keywords (sharex, sharey) to boxplot_frame_groupby and pass it to _subplots() --- pandas/plotting/_core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 87b7d13251f28..1ebf618e6a1da 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2548,7 +2548,7 @@ def plot_group(group, ax): def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None, rot=0, grid=True, ax=None, figsize=None, - layout=None, **kwds): + layout=None, sharex=False, sharey=True, **kwds): """ Make box plots from DataFrameGroupBy data. @@ -2598,7 +2598,7 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None, if subplots is True: naxes = len(grouped) fig, axes = _subplots(naxes=naxes, squeeze=False, - ax=ax, sharex=False, sharey=True, + ax=ax, sharex=sharex, sharey=sharey, figsize=figsize, layout=layout) axes = _flatten(axes) From 8d822b0ab1428baa18594f1bb1736b2bb366108f Mon Sep 17 00:00:00 2001 From: Soren Date: Sun, 6 May 2018 11:02:04 -0600 Subject: [PATCH 02/16] Added documentation for new feature. --- doc/source/whatsnew/v0.23.0.txt | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index eb6c212731822..e8f1020a109e7 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -898,6 +898,48 @@ yourself. To revert to the old setting, you can run this line: pd.options.display.max_columns = 20 +.. _whatsnew_0230.boxplot.sharexy: + +Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +(:issue:`15184`) + +Previous Behavior: + +.. code-block:: jupyter-notebook + + %pylab inline + import pandas as pd + + N = 100 + rand = random.random(N) + clas = random.binomial(5,.5, N) + df = pd.DataFrame({'Rand': rand-clas, + 'Rand2': rand, + 'Class': clas}, + index= np.arange(N)) + + df.groupby('Class').boxplot(sharey=True, sharex=False) + >>> TypeError: boxplot() got an unexpected keyword argument 'sharey' + + Using boxplot with keywords sharex or sharey resulted in an error. + +New Behavior: + +.. ipython:: jpyter-notebook: + + ... + + df.groupby('Class').boxplot(sharey=True, sharex=True) + df.groupby('Class').boxplot(sharey=True, sharex=False) + df.groupby('Class').boxplot(sharey=False, sharex=True) + df.groupby('Class').boxplot(sharey=False, sharex=False) + + All leads to different behaviour. The shareing of axes both x and y + can be turned on and off separately. + +To restore previous behavior, use boxplot() without keywords. + .. _whatsnew_0230.api.datetimelike: Datetimelike API Changes From eb71a8e472d45d1ac8feb51bfe1e3689f7b86d55 Mon Sep 17 00:00:00 2001 From: Soren Date: Wed, 9 May 2018 10:56:11 -0600 Subject: [PATCH 03/16] Added tests for DataFrame.groupby().boxplot()'s sharex and sharey keywords --- pandas/tests/plotting/test_frame.py | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index ac02f5f4e4283..f7d3150054e91 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -367,6 +367,68 @@ def test_subplots(self): for ax in axes: assert ax.get_legend() is None + def test_groupby_boxplot_sharey(self): + # https://github.com/pandas-dev/pandas/issues/9737 using gridspec, + # the axis in fig.get_axis() are sorted differently than pandas + # expected them, so make sure that only the right ones are removed + import matplotlib.pyplot as plt + + df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14], + 'b': [0.56, 0.84, 0.29, 0.56, 0.85,], + 'c': [0, 1, 2, 3, 1]}, + index=[0, 1, 2, 3, 4]) + + # standart behavior + axes = df.groupby('c').boxplot() + self._check_visible(axes[0].get_yticklabels(), visible=True) + self._check_visible(axes[1].get_yticklabels(), visible=False) + self._check_visible(axes[2].get_yticklabels(), visible=True) + self._check_visible(axes[3].get_yticklabels(), visible=False) + # set sharey=True should be identical + axes = df.groupby('c').boxplot(sharey=True) + self._check_visible(axes[0].get_yticklabels(), visible=True) + self._check_visible(axes[1].get_yticklabels(), visible=False) + self._check_visible(axes[2].get_yticklabels(), visible=True) + self._check_visible(axes[3].get_yticklabels(), visible=False) + # sharey=False, all yticklabels should be visible + axes = df.groupby('c').boxplot(sharey=False) + self._check_visible(axes[0].get_yticklabels(), visible=True) + self._check_visible(axes[1].get_yticklabels(), visible=True) + self._check_visible(axes[2].get_yticklabels(), visible=True) + self._check_visible(axes[3].get_yticklabels(), visible=True) + + + def test_groupby_boxplot_sharex(self): + # https://github.com/pandas-dev/pandas/issues/9737 using gridspec, + # the axis in fig.get_axis() are sorted differently than pandas + # expected them, so make sure that only the right ones are removed + import matplotlib.pyplot as plt + + df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14], + 'b': [0.56, 0.84, 0.29, 0.56, 0.85,], + 'c': [0, 1, 2, 3, 1]}, + index=[0, 1, 2, 3, 4]) + + # standart behavior + axes = df.groupby('c').boxplot() + self._check_visible(axes[0].get_xticklabels(), visible=True) + self._check_visible(axes[1].get_xticklabels(), visible=True) + self._check_visible(axes[2].get_xticklabels(), visible=True) + self._check_visible(axes[3].get_xticklabels(), visible=True) + # set sharex=False should be identical + axes = df.groupby('c').boxplot(sharex=False) + self._check_visible(axes[0].get_xticklabels(), visible=True) + self._check_visible(axes[1].get_xticklabels(), visible=True) + self._check_visible(axes[2].get_xticklabels(), visible=True) + self._check_visible(axes[3].get_xticklabels(), visible=True) + # sharex=True, yticklabels should be visible for bottom plots + axes = df.groupby('c').boxplot(sharex=True) + self._check_visible(axes[0].get_xticklabels(), visible=False) + self._check_visible(axes[1].get_xticklabels(), visible=False) + self._check_visible(axes[2].get_xticklabels(), visible=True) + self._check_visible(axes[3].get_xticklabels(), visible=True) + + @pytest.mark.slow def test_subplots_timeseries(self): idx = date_range(start='2014-07-01', freq='M', periods=10) From dc7f3f596351630845e7b83eab9ab7b067780445 Mon Sep 17 00:00:00 2001 From: Soren Date: Wed, 9 May 2018 11:04:35 -0600 Subject: [PATCH 04/16] Flake8 fixed --- pandas/tests/plotting/test_frame.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index f7d3150054e91..c3c6c37020172 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -371,10 +371,9 @@ def test_groupby_boxplot_sharey(self): # https://github.com/pandas-dev/pandas/issues/9737 using gridspec, # the axis in fig.get_axis() are sorted differently than pandas # expected them, so make sure that only the right ones are removed - import matplotlib.pyplot as plt df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14], - 'b': [0.56, 0.84, 0.29, 0.56, 0.85,], + 'b': [0.56, 0.84, 0.29, 0.56, 0.85], 'c': [0, 1, 2, 3, 1]}, index=[0, 1, 2, 3, 4]) @@ -390,22 +389,20 @@ def test_groupby_boxplot_sharey(self): self._check_visible(axes[1].get_yticklabels(), visible=False) self._check_visible(axes[2].get_yticklabels(), visible=True) self._check_visible(axes[3].get_yticklabels(), visible=False) - # sharey=False, all yticklabels should be visible + # sharey=False, all yticklabels should be visible axes = df.groupby('c').boxplot(sharey=False) self._check_visible(axes[0].get_yticklabels(), visible=True) self._check_visible(axes[1].get_yticklabels(), visible=True) self._check_visible(axes[2].get_yticklabels(), visible=True) - self._check_visible(axes[3].get_yticklabels(), visible=True) - + self._check_visible(axes[3].get_yticklabels(), visible=True) def test_groupby_boxplot_sharex(self): # https://github.com/pandas-dev/pandas/issues/9737 using gridspec, # the axis in fig.get_axis() are sorted differently than pandas # expected them, so make sure that only the right ones are removed - import matplotlib.pyplot as plt df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14], - 'b': [0.56, 0.84, 0.29, 0.56, 0.85,], + 'b': [0.56, 0.84, 0.29, 0.56, 0.85], 'c': [0, 1, 2, 3, 1]}, index=[0, 1, 2, 3, 4]) @@ -421,14 +418,13 @@ def test_groupby_boxplot_sharex(self): self._check_visible(axes[1].get_xticklabels(), visible=True) self._check_visible(axes[2].get_xticklabels(), visible=True) self._check_visible(axes[3].get_xticklabels(), visible=True) - # sharex=True, yticklabels should be visible for bottom plots + # sharex=True, yticklabels should be visible for bottom plots axes = df.groupby('c').boxplot(sharex=True) self._check_visible(axes[0].get_xticklabels(), visible=False) self._check_visible(axes[1].get_xticklabels(), visible=False) self._check_visible(axes[2].get_xticklabels(), visible=True) self._check_visible(axes[3].get_xticklabels(), visible=True) - @pytest.mark.slow def test_subplots_timeseries(self): idx = date_range(start='2014-07-01', freq='M', periods=10) From 9cb994ce34f759ef50ec3599df935e4d72a32d91 Mon Sep 17 00:00:00 2001 From: Soren Date: Thu, 17 May 2018 17:39:50 -0600 Subject: [PATCH 05/16] Removed the example from 0.23.0.txt and generated v0.23.1.txt --- doc/source/whatsnew/v0.23.0.txt | 36 +-------------------------------- doc/source/whatsnew/v0.23.1.txt | 7 +++++++ pandas/plotting/_core.py | 6 ++++++ 3 files changed, 14 insertions(+), 35 deletions(-) create mode 100644 doc/source/whatsnew/v0.23.1.txt diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index e8f1020a109e7..f773043c0fffb 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -904,41 +904,7 @@ Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (:issue:`15184`) -Previous Behavior: - -.. code-block:: jupyter-notebook - - %pylab inline - import pandas as pd - - N = 100 - rand = random.random(N) - clas = random.binomial(5,.5, N) - df = pd.DataFrame({'Rand': rand-clas, - 'Rand2': rand, - 'Class': clas}, - index= np.arange(N)) - - df.groupby('Class').boxplot(sharey=True, sharex=False) - >>> TypeError: boxplot() got an unexpected keyword argument 'sharey' - - Using boxplot with keywords sharex or sharey resulted in an error. - -New Behavior: - -.. ipython:: jpyter-notebook: - - ... - - df.groupby('Class').boxplot(sharey=True, sharex=True) - df.groupby('Class').boxplot(sharey=True, sharex=False) - df.groupby('Class').boxplot(sharey=False, sharex=True) - df.groupby('Class').boxplot(sharey=False, sharex=False) - - All leads to different behaviour. The shareing of axes both x and y - can be turned on and off separately. - -To restore previous behavior, use boxplot() without keywords. +Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() .. _whatsnew_0230.api.datetimelike: diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt new file mode 100644 index 0000000000000..c34bab1e1e224 --- /dev/null +++ b/doc/source/whatsnew/v0.23.1.txt @@ -0,0 +1,7 @@ +.. _whatsnew_0231.boxplot.sharexy: + +Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +(:issue:`15184`) + +Boxplot now accepts sharex and sharey keywords. \ No newline at end of file diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 1ebf618e6a1da..5c13de993ff40 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2567,6 +2567,12 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None, figsize : A tuple (width, height) in inches layout : tuple (optional) (rows, columns) for the layout of the plot + sharex : + * ``True`` - x-axes will be shared among subplots + * ``False`` - x-axes will not be shared + sharey : + * ``True`` - y-axes will be shared among subplots + * ``False`` - y-axes will not be shared `**kwds` : Keyword Arguments All other plotting keyword arguments to be passed to matplotlib's boxplot function From 64aac3488b9528f9ec3afe490ca190f15b92762c Mon Sep 17 00:00:00 2001 From: Soren Date: Thu, 17 May 2018 18:14:18 -0600 Subject: [PATCH 06/16] Added comment to Plotting --- doc/source/whatsnew/v0.23.1.txt | 91 +++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 doc/source/whatsnew/v0.23.1.txt diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt new file mode 100644 index 0000000000000..d030e37bc7e50 --- /dev/null +++ b/doc/source/whatsnew/v0.23.1.txt @@ -0,0 +1,91 @@ +.. _whatsnew_0231: + +v0.23.1 +------- + +This is a minor bug-fix release in the 0.23.x series and includes some small regression fixes +and bug fixes. We recommend that all users upgrade to this version. + +.. contents:: What's new in v0.23.1 + :local: + :backlinks: none + +.. _whatsnew_0231.enhancements: + +New features +~~~~~~~~~~~~ + + +.. _whatsnew_0231.deprecations: + +Deprecations +~~~~~~~~~~~~ + +- +- + +.. _whatsnew_0231.performance: + +Performance Improvements +~~~~~~~~~~~~~~~~~~~~~~~~ + +- Improved performance of :meth:`CategoricalIndex.is_monotonic_increasing`, :meth:`CategoricalIndex.is_monotonic_decreasing` and :meth:`CategoricalIndex.is_monotonic` (:issue:`21025`) +- +- + +Documentation Changes +~~~~~~~~~~~~~~~~~~~~~ + +- +- + +.. _whatsnew_0231.bug_fixes: + +Bug Fixes +~~~~~~~~~ + +Groupby/Resample/Rolling +^^^^^^^^^^^^^^^^^^^^^^^^ + +- Bug in :func:`DataFrame.agg` where applying multiple aggregation functions to a :class:`DataFrame` with duplicated column names would cause a stack overflow (:issue:`21063`) + +Strings +^^^^^^^ + +- Bug in :meth:`Series.str.replace()` where the method throws `TypeError` on Python 3.5.2 (:issue: `21078`) +- + +Conversion +^^^^^^^^^^ + +- +- + +Indexing +^^^^^^^^ + +- +- + +I/O +^^^ + +- +- + +Plotting +^^^^^^^^ + +- Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() (:issue:`20968`) +- + +Reshaping +^^^^^^^^^ + +- +- + +Categorical +^^^^^^^^^^^ + +- From 8dc0e9b6a4b9ddb76222854a9c6f33645fc8d5bc Mon Sep 17 00:00:00 2001 From: Soren Date: Fri, 18 May 2018 11:35:53 -0600 Subject: [PATCH 07/16] Added comment regarding new sharex, sharey feature of boxplot() --- doc/source/whatsnew/v0.23.1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt index d030e37bc7e50..b7cdc7bf49e85 100644 --- a/doc/source/whatsnew/v0.23.1.txt +++ b/doc/source/whatsnew/v0.23.1.txt @@ -76,7 +76,7 @@ I/O Plotting ^^^^^^^^ -- Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() (:issue:`20968`) +- Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() (:issue: `20968`) - Reshaping From 6bff510f07195948122b306cad195bc835d9bf75 Mon Sep 17 00:00:00 2001 From: Soren Date: Fri, 18 May 2018 11:39:06 -0600 Subject: [PATCH 08/16] Made tests for sharex, sharey keywords of boxplot shorter. --- pandas/tests/plotting/test_frame.py | 59 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index c3c6c37020172..4e100988111d0 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -368,9 +368,13 @@ def test_subplots(self): assert ax.get_legend() is None def test_groupby_boxplot_sharey(self): - # https://github.com/pandas-dev/pandas/issues/9737 using gridspec, - # the axis in fig.get_axis() are sorted differently than pandas - # expected them, so make sure that only the right ones are removed + # https://github.com/pandas-dev/pandas/issues/20968 + # sharey can now be switched check whether the right + # pair of axes is turned on or off + + def _assert_ytickslabels_visibility(axes, expected): + for ax, exp in zip(axes, expected): + self._check_visible(ax.get_yticklabels(), visible=exp) df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14], 'b': [0.56, 0.84, 0.29, 0.56, 0.85], @@ -379,27 +383,25 @@ def test_groupby_boxplot_sharey(self): # standart behavior axes = df.groupby('c').boxplot() - self._check_visible(axes[0].get_yticklabels(), visible=True) - self._check_visible(axes[1].get_yticklabels(), visible=False) - self._check_visible(axes[2].get_yticklabels(), visible=True) - self._check_visible(axes[3].get_yticklabels(), visible=False) + expected = [True, False, True, False] + _assert_ytickslabels_visibility(axes, expected) # set sharey=True should be identical axes = df.groupby('c').boxplot(sharey=True) - self._check_visible(axes[0].get_yticklabels(), visible=True) - self._check_visible(axes[1].get_yticklabels(), visible=False) - self._check_visible(axes[2].get_yticklabels(), visible=True) - self._check_visible(axes[3].get_yticklabels(), visible=False) + expected = [True, False, True, False] + _assert_ytickslabels_visibility(axes, expected) # sharey=False, all yticklabels should be visible axes = df.groupby('c').boxplot(sharey=False) - self._check_visible(axes[0].get_yticklabels(), visible=True) - self._check_visible(axes[1].get_yticklabels(), visible=True) - self._check_visible(axes[2].get_yticklabels(), visible=True) - self._check_visible(axes[3].get_yticklabels(), visible=True) + expected = [True, True, True, True] + _assert_ytickslabels_visibility(axes, expected) def test_groupby_boxplot_sharex(self): - # https://github.com/pandas-dev/pandas/issues/9737 using gridspec, - # the axis in fig.get_axis() are sorted differently than pandas - # expected them, so make sure that only the right ones are removed + # https://github.com/pandas-dev/pandas/issues/20968 + # sharex can now be switched check whether the right + # pair of axes is turned on or off + + def _assert_xtickslabels_visibility(axes, expected): + for ax, exp in zip(axes, expected): + self._check_visible(ax.get_xticklabels(), visible=exp) df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14], 'b': [0.56, 0.84, 0.29, 0.56, 0.85], @@ -408,22 +410,17 @@ def test_groupby_boxplot_sharex(self): # standart behavior axes = df.groupby('c').boxplot() - self._check_visible(axes[0].get_xticklabels(), visible=True) - self._check_visible(axes[1].get_xticklabels(), visible=True) - self._check_visible(axes[2].get_xticklabels(), visible=True) - self._check_visible(axes[3].get_xticklabels(), visible=True) + expected = [True, True, True, True] + _assert_xtickslabels_visibility(axes, expected) # set sharex=False should be identical axes = df.groupby('c').boxplot(sharex=False) - self._check_visible(axes[0].get_xticklabels(), visible=True) - self._check_visible(axes[1].get_xticklabels(), visible=True) - self._check_visible(axes[2].get_xticklabels(), visible=True) - self._check_visible(axes[3].get_xticklabels(), visible=True) - # sharex=True, yticklabels should be visible for bottom plots + expected = [True, True, True, True] + _assert_xtickslabels_visibility(axes, expected) + # sharex=True, yticklabels should be visible + # only for bottom plots axes = df.groupby('c').boxplot(sharex=True) - self._check_visible(axes[0].get_xticklabels(), visible=False) - self._check_visible(axes[1].get_xticklabels(), visible=False) - self._check_visible(axes[2].get_xticklabels(), visible=True) - self._check_visible(axes[3].get_xticklabels(), visible=True) + expected = [False, False, True, True] + _assert_xtickslabels_visibility(axes, expected) @pytest.mark.slow def test_subplots_timeseries(self): From cfc0a5fff1d41cefc389f68c88f35b1959e267db Mon Sep 17 00:00:00 2001 From: Soren Date: Sat, 19 May 2018 14:44:19 -0600 Subject: [PATCH 09/16] Formated docstring --- pandas/plotting/_core.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 5c13de993ff40..fd7450deb1dbc 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2567,12 +2567,10 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None, figsize : A tuple (width, height) in inches layout : tuple (optional) (rows, columns) for the layout of the plot - sharex : - * ``True`` - x-axes will be shared among subplots - * ``False`` - x-axes will not be shared - sharey : - * ``True`` - y-axes will be shared among subplots - * ``False`` - y-axes will not be shared + sharex : bool, default False + Whether x-axes will be shared among subplots + sharey : bool, default True + Whether y-axes will be shared among subplots `**kwds` : Keyword Arguments All other plotting keyword arguments to be passed to matplotlib's boxplot function From 6c0c3240e15250a9a788ddca1703d2cc99382c69 Mon Sep 17 00:00:00 2001 From: Soren Date: Mon, 28 May 2018 22:19:07 -0600 Subject: [PATCH 10/16] Added blank lines between cases --- pandas/tests/plotting/test_frame.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 4e100988111d0..17bb9cdcd76c2 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -385,10 +385,12 @@ def _assert_ytickslabels_visibility(axes, expected): axes = df.groupby('c').boxplot() expected = [True, False, True, False] _assert_ytickslabels_visibility(axes, expected) + # set sharey=True should be identical axes = df.groupby('c').boxplot(sharey=True) expected = [True, False, True, False] _assert_ytickslabels_visibility(axes, expected) + # sharey=False, all yticklabels should be visible axes = df.groupby('c').boxplot(sharey=False) expected = [True, True, True, True] @@ -412,10 +414,12 @@ def _assert_xtickslabels_visibility(axes, expected): axes = df.groupby('c').boxplot() expected = [True, True, True, True] _assert_xtickslabels_visibility(axes, expected) + # set sharex=False should be identical axes = df.groupby('c').boxplot(sharex=False) expected = [True, True, True, True] _assert_xtickslabels_visibility(axes, expected) + # sharex=True, yticklabels should be visible # only for bottom plots axes = df.groupby('c').boxplot(sharex=True) From e0a55152e9bc8d897d5590cf199211cfee428282 Mon Sep 17 00:00:00 2001 From: Soren Date: Tue, 29 May 2018 11:53:45 -0600 Subject: [PATCH 11/16] added versionadded tag --- pandas/plotting/_core.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index fd7450deb1dbc..fb1f465ee9e41 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2569,8 +2569,12 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None, (rows, columns) for the layout of the plot sharex : bool, default False Whether x-axes will be shared among subplots + + .. versionadded:: 0.23.1 sharey : bool, default True Whether y-axes will be shared among subplots + + .. versionadded:: 0.23.1 `**kwds` : Keyword Arguments All other plotting keyword arguments to be passed to matplotlib's boxplot function From 6b4d37122fbe28f891e3eb84195827796779b60e Mon Sep 17 00:00:00 2001 From: Soren Date: Wed, 6 Jun 2018 12:52:53 -0600 Subject: [PATCH 12/16] reverted v0.23.0.txt --- doc/source/whatsnew/v0.23.0.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index efdef8faa9f8f..a099fb40c35a7 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -927,14 +927,6 @@ yourself. To revert to the old setting, you can run this line: pd.options.display.max_columns = 20 -.. _whatsnew_0230.boxplot.sharexy: - -Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -(:issue:`15184`) - -Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() - .. _whatsnew_0230.api.datetimelike: Datetimelike API Changes From c1d5cabbcbfb33179cb8a0d54a60cb2a0048e6d3 Mon Sep 17 00:00:00 2001 From: Soren Date: Wed, 6 Jun 2018 12:57:07 -0600 Subject: [PATCH 13/16] Moved helper functions out of test cases; clarification of comments for tests without keywords --- pandas/tests/plotting/test_frame.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 17bb9cdcd76c2..8ddb2f259a6b4 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -372,16 +372,12 @@ def test_groupby_boxplot_sharey(self): # sharey can now be switched check whether the right # pair of axes is turned on or off - def _assert_ytickslabels_visibility(axes, expected): - for ax, exp in zip(axes, expected): - self._check_visible(ax.get_yticklabels(), visible=exp) - df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14], 'b': [0.56, 0.84, 0.29, 0.56, 0.85], 'c': [0, 1, 2, 3, 1]}, index=[0, 1, 2, 3, 4]) - # standart behavior + # behavior without keyword axes = df.groupby('c').boxplot() expected = [True, False, True, False] _assert_ytickslabels_visibility(axes, expected) @@ -396,21 +392,21 @@ def _assert_ytickslabels_visibility(axes, expected): expected = [True, True, True, True] _assert_ytickslabels_visibility(axes, expected) + def _assert_ytickslabels_visibility(axes, expected): + for ax, exp in zip(axes, expected): + self._check_visible(ax.get_yticklabels(), visible=exp) + def test_groupby_boxplot_sharex(self): # https://github.com/pandas-dev/pandas/issues/20968 # sharex can now be switched check whether the right # pair of axes is turned on or off - def _assert_xtickslabels_visibility(axes, expected): - for ax, exp in zip(axes, expected): - self._check_visible(ax.get_xticklabels(), visible=exp) - df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14], 'b': [0.56, 0.84, 0.29, 0.56, 0.85], 'c': [0, 1, 2, 3, 1]}, index=[0, 1, 2, 3, 4]) - # standart behavior + # behavior without keyword axes = df.groupby('c').boxplot() expected = [True, True, True, True] _assert_xtickslabels_visibility(axes, expected) @@ -426,6 +422,10 @@ def _assert_xtickslabels_visibility(axes, expected): expected = [False, False, True, True] _assert_xtickslabels_visibility(axes, expected) + def _assert_xtickslabels_visibility(axes, expected): + for ax, exp in zip(axes, expected): + self._check_visible(ax.get_xticklabels(), visible=exp) + @pytest.mark.slow def test_subplots_timeseries(self): idx = date_range(start='2014-07-01', freq='M', periods=10) From 26ef59866895a522d7fac906aaf02e8b66b26d78 Mon Sep 17 00:00:00 2001 From: Soren Date: Wed, 6 Jun 2018 16:09:20 -0600 Subject: [PATCH 14/16] Moved helper functions out of test cases, and fixed them --- pandas/tests/plotting/test_frame.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 8ddb2f259a6b4..aac0baf482cd8 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -380,21 +380,17 @@ def test_groupby_boxplot_sharey(self): # behavior without keyword axes = df.groupby('c').boxplot() expected = [True, False, True, False] - _assert_ytickslabels_visibility(axes, expected) + self._assert_ytickslabels_visibility(axes, expected) # set sharey=True should be identical axes = df.groupby('c').boxplot(sharey=True) expected = [True, False, True, False] - _assert_ytickslabels_visibility(axes, expected) + self._assert_ytickslabels_visibility(axes, expected) # sharey=False, all yticklabels should be visible axes = df.groupby('c').boxplot(sharey=False) expected = [True, True, True, True] - _assert_ytickslabels_visibility(axes, expected) - - def _assert_ytickslabels_visibility(axes, expected): - for ax, exp in zip(axes, expected): - self._check_visible(ax.get_yticklabels(), visible=exp) + self._assert_ytickslabels_visibility(axes, expected) def test_groupby_boxplot_sharex(self): # https://github.com/pandas-dev/pandas/issues/20968 @@ -409,22 +405,18 @@ def test_groupby_boxplot_sharex(self): # behavior without keyword axes = df.groupby('c').boxplot() expected = [True, True, True, True] - _assert_xtickslabels_visibility(axes, expected) + self._assert_xtickslabels_visibility(axes, expected) # set sharex=False should be identical axes = df.groupby('c').boxplot(sharex=False) expected = [True, True, True, True] - _assert_xtickslabels_visibility(axes, expected) + self._assert_xtickslabels_visibility(axes, expected) # sharex=True, yticklabels should be visible # only for bottom plots axes = df.groupby('c').boxplot(sharex=True) expected = [False, False, True, True] - _assert_xtickslabels_visibility(axes, expected) - - def _assert_xtickslabels_visibility(axes, expected): - for ax, exp in zip(axes, expected): - self._check_visible(ax.get_xticklabels(), visible=exp) + self._assert_xtickslabels_visibility(axes, expected) @pytest.mark.slow def test_subplots_timeseries(self): @@ -2980,6 +2972,14 @@ def test_secondary_axis_font_size(self, method): self._check_ticks_props(axes=ax.right_ax, ylabelsize=fontsize) + def _assert_ytickslabels_visibility(self, axes, expected): + for ax, exp in zip(axes, expected): + self._check_visible(ax.get_yticklabels(), visible=exp) + + def _assert_xtickslabels_visibility(self, axes, expected): + for ax, exp in zip(axes, expected): + self._check_visible(ax.get_xticklabels(), visible=exp) + def _generate_4_axes_via_gridspec(): import matplotlib.pyplot as plt From 42d72865bff81518901e5035bd62b848f606c2d3 Mon Sep 17 00:00:00 2001 From: Soren Date: Thu, 7 Jun 2018 09:43:17 -0600 Subject: [PATCH 15/16] Moved helper functions to the top; clarified doc string --- doc/source/whatsnew/v0.23.1.txt | 2 +- pandas/tests/plotting/test_frame.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt index b7cdc7bf49e85..64252eeca5c98 100644 --- a/doc/source/whatsnew/v0.23.1.txt +++ b/doc/source/whatsnew/v0.23.1.txt @@ -76,7 +76,7 @@ I/O Plotting ^^^^^^^^ -- Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() (:issue: `20968`) +- New keywords (sharex, sharey) to turn on/off sharing of x/y-axis by subplots generated with pandas.DataFrame().groupby().boxplot() (:issue: `20968`) - Reshaping diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index aac0baf482cd8..101713b06df8c 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -40,6 +40,14 @@ def setup_method(self, method): "C": np.arange(20) + np.random.uniform( size=20)}) + def _assert_ytickslabels_visibility(self, axes, expected): + for ax, exp in zip(axes, expected): + self._check_visible(ax.get_yticklabels(), visible=exp) + + def _assert_xtickslabels_visibility(self, axes, expected): + for ax, exp in zip(axes, expected): + self._check_visible(ax.get_xticklabels(), visible=exp) + @pytest.mark.slow def test_plot(self): df = self.tdf @@ -2972,14 +2980,6 @@ def test_secondary_axis_font_size(self, method): self._check_ticks_props(axes=ax.right_ax, ylabelsize=fontsize) - def _assert_ytickslabels_visibility(self, axes, expected): - for ax, exp in zip(axes, expected): - self._check_visible(ax.get_yticklabels(), visible=exp) - - def _assert_xtickslabels_visibility(self, axes, expected): - for ax, exp in zip(axes, expected): - self._check_visible(ax.get_xticklabels(), visible=exp) - def _generate_4_axes_via_gridspec(): import matplotlib.pyplot as plt From fd76955c41ced7f46f428efc736dafb59ba5246e Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Fri, 8 Jun 2018 07:24:56 -0400 Subject: [PATCH 16/16] add sub-section highlites --- doc/source/whatsnew/v0.23.1.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt index a0c007958c641..5a1bcce9b5970 100644 --- a/doc/source/whatsnew/v0.23.1.txt +++ b/doc/source/whatsnew/v0.23.1.txt @@ -48,22 +48,26 @@ Bug Fixes ~~~~~~~~~ Groupby/Resample/Rolling +~~~~~~~~~~~~~~~~~~~~~~~~ - Bug in :func:`DataFrame.agg` where applying multiple aggregation functions to a :class:`DataFrame` with duplicated column names would cause a stack overflow (:issue:`21063`) - Bug in :func:`pandas.core.groupby.GroupBy.ffill` and :func:`pandas.core.groupby.GroupBy.bfill` where the fill within a grouping would not always be applied as intended due to the implementations' use of a non-stable sort (:issue:`21207`) - Bug in :func:`pandas.core.groupby.GroupBy.rank` where results did not scale to 100% when specifying ``method='dense'`` and ``pct=True`` Data-type specific +~~~~~~~~~~~~~~~~~~ - Bug in :meth:`Series.str.replace()` where the method throws `TypeError` on Python 3.5.2 (:issue: `21078`) - Bug in :class:`Timedelta`: where passing a float with a unit would prematurely round the float precision (:issue: `14156`) - Bug in :func:`pandas.testing.assert_index_equal` which raised ``AssertionError`` incorrectly, when comparing two :class:`CategoricalIndex` objects with param ``check_categorical=False`` (:issue:`19776`) Sparse +~~~~~~ - Bug in :attr:`SparseArray.shape` which previously only returned the shape :attr:`SparseArray.sp_values` (:issue:`21126`) Indexing +~~~~~~~~ - Bug in :meth:`Series.reset_index` where appropriate error was not raised with an invalid level name (:issue:`20925`) - Bug in :func:`interval_range` when ``start``/``periods`` or ``end``/``periods`` are specified with float ``start`` or ``end`` (:issue:`21161`) @@ -72,10 +76,12 @@ Indexing - Bug in :meth:`MultiIndex.sort_index` which was not guaranteed to sort correctly with ``level=1``; this was also causing data misalignment in particular :meth:`DataFrame.stack` operations (:issue:`20994`, :issue:`20945`, :issue:`21052`) Plotting +~~~~~~~~ - New keywords (sharex, sharey) to turn on/off sharing of x/y-axis by subplots generated with pandas.DataFrame().groupby().boxplot() (:issue: `20968`) I/O +~~~ - Bug in IO methods specifying ``compression='zip'`` which produced uncompressed zip archives (:issue:`17778`, :issue:`21144`) - Bug in :meth:`DataFrame.to_stata` which prevented exporting DataFrames to buffers and most file-like objects (:issue:`21041`) @@ -83,10 +89,12 @@ I/O Reshaping +~~~~~~~~~ - Bug in :func:`concat` where error was raised in concatenating :class:`Series` with numpy scalar and tuple names (:issue:`21015`) - Bug in :func:`concat` warning message providing the wrong guidance for future behavior (:issue:`21101`) Other +~~~~~ - Tab completion on :class:`Index` in IPython no longer outputs deprecation warnings (:issue:`21125`)