From 7e461a18d9f6928132afec6f48ce968b3e989ba6 Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Mon, 3 Dec 2018 17:43:52 +0100 Subject: [PATCH 01/10] remove \n from docstring --- pandas/core/arrays/datetimes.py | 26 +++++++++++++------------- pandas/core/arrays/timedeltas.py | 16 ++++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index cfe3afcf3730a..b3df505d56d78 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -82,7 +82,7 @@ def f(self): return result f.__name__ = name - f.__doc__ = docstring + f.__doc__ = "\n{}\n".format(docstring) return property(f) @@ -1072,19 +1072,19 @@ def date(self): return tslib.ints_to_pydatetime(timestamps, box="date") - year = _field_accessor('year', 'Y', "\n The year of the datetime\n") + year = _field_accessor('year', 'Y', "The year of the datetime") month = _field_accessor('month', 'M', - "\n The month as January=1, December=12 \n") - day = _field_accessor('day', 'D', "\nThe days of the datetime\n") - hour = _field_accessor('hour', 'h', "\nThe hours of the datetime\n") - minute = _field_accessor('minute', 'm', "\nThe minutes of the datetime\n") - second = _field_accessor('second', 's', "\nThe seconds of the datetime\n") + "The month as January=1, December=12") + day = _field_accessor('day', 'D', "The days of the datetime") + hour = _field_accessor('hour', 'h', "The hours of the datetime") + minute = _field_accessor('minute', 'm', "The minutes of the datetime") + second = _field_accessor('second', 's', "The seconds of the datetime") microsecond = _field_accessor('microsecond', 'us', - "\nThe microseconds of the datetime\n") + "The microseconds of the datetime") nanosecond = _field_accessor('nanosecond', 'ns', - "\nThe nanoseconds of the datetime\n") + "The nanoseconds of the datetime") weekofyear = _field_accessor('weekofyear', 'woy', - "\nThe week ordinal of the year\n") + "The week ordinal of the year") week = weekofyear _dayofweek_doc = """ The day of the week with Monday=0, Sunday=6. @@ -1129,12 +1129,12 @@ def date(self): "The name of day in a week (ex: Friday)\n\n.. deprecated:: 0.23.0") dayofyear = _field_accessor('dayofyear', 'doy', - "\nThe ordinal day of the year\n") - quarter = _field_accessor('quarter', 'q', "\nThe quarter of the date\n") + "The ordinal day of the year") + quarter = _field_accessor('quarter', 'q', "The quarter of the date") days_in_month = _field_accessor( 'days_in_month', 'dim', - "\nThe number of days in the month\n") + "The number of days in the month") daysinmonth = days_in_month _is_month_doc = """ Indicates whether the date is the {first_or_last} day of the month. diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 830283d31a929..4afc9f5483c2a 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -59,7 +59,7 @@ def f(self): return result f.__name__ = name - f.__doc__ = docstring + f.__doc__ = "\n{}\n".format(docstring) return property(f) @@ -684,16 +684,16 @@ def to_pytimedelta(self): return tslibs.ints_to_pytimedelta(self.asi8) days = _field_accessor("days", "days", - "\nNumber of days for each element.\n") + "Number of days for each element.") seconds = _field_accessor("seconds", "seconds", - "\nNumber of seconds (>= 0 and less than 1 day) " - "for each element.\n") + "Number of seconds (>= 0 and less than 1 day) " + "for each element.") microseconds = _field_accessor("microseconds", "microseconds", - "\nNumber of microseconds (>= 0 and less " - "than 1 second) for each element.\n") + "Number of microseconds (>= 0 and less " + "than 1 second) for each element.") nanoseconds = _field_accessor("nanoseconds", "nanoseconds", - "\nNumber of nanoseconds (>= 0 and less " - "than 1 microsecond) for each element.\n") + "Number of nanoseconds (>= 0 and less " + "than 1 microsecond) for each element.") @property def components(self): From fc320764de00b9f389b686a70659d81972ddbc94 Mon Sep 17 00:00:00 2001 From: charlesdong1991 Date: Tue, 30 Jul 2019 23:03:19 +0200 Subject: [PATCH 02/10] Allow plot boolean --- pandas/plotting/_matplotlib/__init__.py | 4 ++-- pandas/plotting/_matplotlib/core.py | 11 +++++++---- pandas/tests/plotting/test_series.py | 8 ++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pandas/plotting/_matplotlib/__init__.py b/pandas/plotting/_matplotlib/__init__.py index d3b7a34b6c923..29d071defa3f4 100644 --- a/pandas/plotting/_matplotlib/__init__.py +++ b/pandas/plotting/_matplotlib/__init__.py @@ -46,7 +46,7 @@ register(explicit=False) -def plot(data, kind, **kwargs): +def plot(data, kind, include_bool=False, **kwargs): # Importing pyplot at the top of the file (before the converters are # registered) causes problems in matplotlib 2 (converters seem to not # work) @@ -59,7 +59,7 @@ def plot(data, kind, **kwargs): ax = plt.gca() kwargs["ax"] = getattr(ax, "left_ax", ax) plot_obj = PLOT_CLASSES[kind](data, **kwargs) - plot_obj.generate() + plot_obj.generate(include_bool=include_bool) plot_obj.draw() return plot_obj.result diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 519465802085b..94d7114ac36f1 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -274,9 +274,9 @@ def nseries(self): def draw(self): self.plt.draw_if_interactive() - def generate(self): + def generate(self, include_bool=False): self._args_adjust() - self._compute_plot_data() + self._compute_plot_data(include_bool=include_bool) self._setup_subplots() self._make_plot() self._add_table() @@ -388,7 +388,7 @@ def result(self): else: return self.axes[0] - def _compute_plot_data(self): + def _compute_plot_data(self, include_bool=False): data = self.data if isinstance(data, ABCSeries): @@ -400,8 +400,11 @@ def _compute_plot_data(self): # GH16953, _convert is needed as fallback, for ``Series`` # with ``dtype == object`` data = data._convert(datetime=True, timedelta=True) + select_include_type = [np.number, "datetime", "datetimetz", "timedelta"] + if include_bool: + select_include_type.append(np.bool_) numeric_data = data.select_dtypes( - include=[np.number, "datetime", "datetimetz", "timedelta"] + include=select_include_type ) try: diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 8b4a78e9195b5..b29975ef318a6 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -167,6 +167,14 @@ def test_label(self): ax.legend() # draw it self._check_legend_labels(ax, labels=["LABEL"]) + def test_boolean(self): + s = Series([False, False, True]) + _check_plot_works(s.plot, include_bool=True) + + msg = 'no numeric data to plot' + with pytest.raises(TypeError, match=msg): + _check_plot_works(s.plot) + def test_line_area_nan_series(self): values = [1, 2, np.nan, 3] s = Series(values) From 8abc20f31638e527a0cce34fbfa84be5115d53e0 Mon Sep 17 00:00:00 2001 From: charlesdong1991 Date: Wed, 31 Jul 2019 20:06:58 +0200 Subject: [PATCH 03/10] Mark issue number in test --- pandas/plotting/_matplotlib/core.py | 2 +- pandas/tests/plotting/test_series.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 94d7114ac36f1..724713a74faa4 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -401,7 +401,7 @@ def _compute_plot_data(self, include_bool=False): # with ``dtype == object`` data = data._convert(datetime=True, timedelta=True) select_include_type = [np.number, "datetime", "datetimetz", "timedelta"] - if include_bool: + if include_bool is True: select_include_type.append(np.bool_) numeric_data = data.select_dtypes( include=select_include_type diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index b29975ef318a6..0ec4ebdff65a4 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -168,6 +168,7 @@ def test_label(self): self._check_legend_labels(ax, labels=["LABEL"]) def test_boolean(self): + # GH 23719 s = Series([False, False, True]) _check_plot_works(s.plot, include_bool=True) From ec14f2b57fb2bf3a78ce20257a26ae9be4f86908 Mon Sep 17 00:00:00 2001 From: charlesdong1991 Date: Wed, 31 Jul 2019 21:01:50 +0200 Subject: [PATCH 04/10] Change the boolean option --- pandas/plotting/_matplotlib/__init__.py | 4 ++-- pandas/plotting/_matplotlib/core.py | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pandas/plotting/_matplotlib/__init__.py b/pandas/plotting/_matplotlib/__init__.py index 29d071defa3f4..d3b7a34b6c923 100644 --- a/pandas/plotting/_matplotlib/__init__.py +++ b/pandas/plotting/_matplotlib/__init__.py @@ -46,7 +46,7 @@ register(explicit=False) -def plot(data, kind, include_bool=False, **kwargs): +def plot(data, kind, **kwargs): # Importing pyplot at the top of the file (before the converters are # registered) causes problems in matplotlib 2 (converters seem to not # work) @@ -59,7 +59,7 @@ def plot(data, kind, include_bool=False, **kwargs): ax = plt.gca() kwargs["ax"] = getattr(ax, "left_ax", ax) plot_obj = PLOT_CLASSES[kind](data, **kwargs) - plot_obj.generate(include_bool=include_bool) + plot_obj.generate() plot_obj.draw() return plot_obj.result diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 724713a74faa4..9f35266734bbe 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -106,6 +106,7 @@ def __init__( colormap=None, table=False, layout=None, + include_bool=False, **kwds ): @@ -191,6 +192,7 @@ def __init__( self.colormap = colormap self.table = table + self.include_bool = include_bool self.kwds = kwds @@ -274,9 +276,9 @@ def nseries(self): def draw(self): self.plt.draw_if_interactive() - def generate(self, include_bool=False): + def generate(self): self._args_adjust() - self._compute_plot_data(include_bool=include_bool) + self._compute_plot_data() self._setup_subplots() self._make_plot() self._add_table() @@ -388,7 +390,7 @@ def result(self): else: return self.axes[0] - def _compute_plot_data(self, include_bool=False): + def _compute_plot_data(self): data = self.data if isinstance(data, ABCSeries): @@ -401,11 +403,11 @@ def _compute_plot_data(self, include_bool=False): # with ``dtype == object`` data = data._convert(datetime=True, timedelta=True) select_include_type = [np.number, "datetime", "datetimetz", "timedelta"] - if include_bool is True: + + # GH23719, allow plotting boolean + if self.include_bool is True: select_include_type.append(np.bool_) - numeric_data = data.select_dtypes( - include=select_include_type - ) + numeric_data = data.select_dtypes(include=select_include_type) try: is_empty = numeric_data.empty From 951ede40fc649f0e660e8a6560bc7e3cacc338ac Mon Sep 17 00:00:00 2001 From: charlesdong1991 Date: Wed, 31 Jul 2019 21:29:17 +0200 Subject: [PATCH 05/10] Fix linting error --- pandas/tests/plotting/test_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 0ec4ebdff65a4..111c3a70fc09c 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -172,7 +172,7 @@ def test_boolean(self): s = Series([False, False, True]) _check_plot_works(s.plot, include_bool=True) - msg = 'no numeric data to plot' + msg = "no numeric data to plot" with pytest.raises(TypeError, match=msg): _check_plot_works(s.plot) From 057fdf138a6061f8c9c27f39cdedccb0a2a42247 Mon Sep 17 00:00:00 2001 From: charlesdong1991 Date: Wed, 31 Jul 2019 22:00:31 +0200 Subject: [PATCH 06/10] Add docstring and whatsnew --- doc/source/whatsnew/v1.0.0.rst | 2 +- pandas/plotting/_core.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index cc4bab8b9a923..1af449a6e24d3 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -158,7 +158,7 @@ I/O Plotting ^^^^^^^^ -- +- BUG in :meth:`Series.plot` not able to plot boolean data (:issue:`23719`) - Groupby/resample/rolling diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index a3c1499845c2a..ec5c609c1b267 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -586,6 +586,8 @@ class PlotAccessor(PandasObject): mark_right : bool, default True When using a secondary_y axis, automatically mark the column labels with "(right)" in the legend + include_bool : bool, default is False + If True, boolean values can be plotted `**kwds` : keywords Options to pass to matplotlib plotting method From 2167f6124ddaa0d75d730930917b1be5c884bc36 Mon Sep 17 00:00:00 2001 From: charlesdong1991 Date: Mon, 5 Aug 2019 20:40:36 +0200 Subject: [PATCH 07/10] Change a mispelling in whatsnew --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 1af449a6e24d3..13732458b4955 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -158,7 +158,7 @@ I/O Plotting ^^^^^^^^ -- BUG in :meth:`Series.plot` not able to plot boolean data (:issue:`23719`) +- Bug in :meth:`Series.plot` not able to plot boolean data (:issue:`23719`) - Groupby/resample/rolling From a027512cde21448e56a89d8d6cdaffdc46bd4f7f Mon Sep 17 00:00:00 2001 From: charlesdong1991 Date: Tue, 6 Aug 2019 08:36:20 +0200 Subject: [PATCH 08/10] Resubmit PR --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 13732458b4955..c2e22ce387762 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -158,7 +158,7 @@ I/O Plotting ^^^^^^^^ -- Bug in :meth:`Series.plot` not able to plot boolean data (:issue:`23719`) +- Bug in :meth:`Series.plot` not able to plot boolean values (:issue:`23719`) - Groupby/resample/rolling From 9151ea726da912bcb67bcf6af558b2262dd3bbf3 Mon Sep 17 00:00:00 2001 From: charlesdong1991 Date: Thu, 8 Aug 2019 20:45:27 +0200 Subject: [PATCH 09/10] Try update version --- ci/deps/azure-37-locale.yaml | 4 ++-- ci/deps/travis-37.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/deps/azure-37-locale.yaml b/ci/deps/azure-37-locale.yaml index 05adbf0c924dc..77669ab87a814 100644 --- a/ci/deps/azure-37-locale.yaml +++ b/ci/deps/azure-37-locale.yaml @@ -26,8 +26,8 @@ dependencies: - xlsxwriter - xlwt # universal - - pytest>=4.0.2 - - pytest-xdist + - pytest>=5.0.0 + - pytest-xdist>=1.29.0 - pytest-mock - pytest-azurepipelines - pip diff --git a/ci/deps/travis-37.yaml b/ci/deps/travis-37.yaml index c9a8c274fb144..9e08c41a3d9c0 100644 --- a/ci/deps/travis-37.yaml +++ b/ci/deps/travis-37.yaml @@ -13,8 +13,8 @@ dependencies: - pyarrow - pytz # universal - - pytest>=4.0.2 - - pytest-xdist + - pytest>=5.0.0 + - pytest-xdist>=1.29.0 - pytest-mock - hypothesis>=3.58.0 - s3fs From bbb11f309562a13892383eb4b823bcacac83b4b1 Mon Sep 17 00:00:00 2001 From: charlesdong1991 Date: Fri, 9 Aug 2019 19:41:09 +0200 Subject: [PATCH 10/10] Remove ci changes --- ci/deps/azure-37-locale.yaml | 4 ++-- ci/deps/travis-37.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/deps/azure-37-locale.yaml b/ci/deps/azure-37-locale.yaml index 77669ab87a814..05adbf0c924dc 100644 --- a/ci/deps/azure-37-locale.yaml +++ b/ci/deps/azure-37-locale.yaml @@ -26,8 +26,8 @@ dependencies: - xlsxwriter - xlwt # universal - - pytest>=5.0.0 - - pytest-xdist>=1.29.0 + - pytest>=4.0.2 + - pytest-xdist - pytest-mock - pytest-azurepipelines - pip diff --git a/ci/deps/travis-37.yaml b/ci/deps/travis-37.yaml index 9e08c41a3d9c0..c9a8c274fb144 100644 --- a/ci/deps/travis-37.yaml +++ b/ci/deps/travis-37.yaml @@ -13,8 +13,8 @@ dependencies: - pyarrow - pytz # universal - - pytest>=5.0.0 - - pytest-xdist>=1.29.0 + - pytest>=4.0.2 + - pytest-xdist - pytest-mock - hypothesis>=3.58.0 - s3fs