From 7e461a18d9f6928132afec6f48ce968b3e989ba6 Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Mon, 3 Dec 2018 17:43:52 +0100 Subject: [PATCH 1/9] 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 642281d8757088b1205d9f46aa2bc7684ad60253 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Tue, 26 Nov 2019 15:11:43 +0100 Subject: [PATCH 2/9] Add progress bar type for read_gbq --- pandas/io/gbq.py | 24 ++++++++++++++++++++++++ pandas/tests/io/test_gbq.py | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index b120de1b3011a..3dd5e684a83e5 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -27,6 +27,7 @@ def read_gbq( use_bqstorage_api=None, private_key=None, verbose=None, + progress_bar_type="tqdm", ): """ Load data from Google BigQuery. @@ -134,6 +135,27 @@ def read_gbq( Deprecated in pandas-gbq version 0.4.0. Use the `logging module to adjust verbosity instead `__. + progress_bar_type (Optional[str]): + If set, use the `tqdm `_ library to + display a progress bar while the data downloads. Install the + ``tqdm`` package to use this feature. + Possible values of ``progress_bar_type`` include: + ``None`` + No progress bar. + ``'tqdm'`` + Use the :func:`tqdm.tqdm` function to print a progress bar + to :data:`sys.stderr`. + ``'tqdm_notebook'`` + Use the :func:`tqdm.tqdm_notebook` function to display a + progress bar as a Jupyter notebook widget. + ``'tqdm_gui'`` + Use the :func:`tqdm.tqdm_gui` function to display a + progress bar as a graphical dialog box. + + This feature requires version 0.12.0 or later of the ``pandas-gbq`` + package. It also requires the ``tqdm`` package. + + .. versionadded:: 1.0.0 Returns ------- @@ -152,6 +174,8 @@ def read_gbq( # START: new kwargs. Don't populate unless explicitly set. if use_bqstorage_api is not None: kwargs["use_bqstorage_api"] = use_bqstorage_api + + kwargs["progress_bar_type"] = progress_bar_type # END: new kwargs # START: deprecated kwargs. Don't populate unless explicitly set. diff --git a/pandas/tests/io/test_gbq.py b/pandas/tests/io/test_gbq.py index 52147f4e1afc7..42596b98912cf 100644 --- a/pandas/tests/io/test_gbq.py +++ b/pandas/tests/io/test_gbq.py @@ -144,6 +144,21 @@ def mock_read_gbq(sql, **kwargs): assert "use_bqstorage_api" not in captured_kwargs +@pytest.mark.parametrize("progress_bar", [None, "foo"]) +def test_read_gbq_progress_bar_type_kwarg(monkeypatch, progress_bar): + # GH 29857 + captured_kwargs = {} + + def mock_read_gbq(sql, **kwargs): + captured_kwargs.update(kwargs) + return DataFrame([[1.0]]) + + monkeypatch.setattr("pandas_gbq.read_gbq", mock_read_gbq) + pd.read_gbq("SELECT 1", progress_bar_type=progress_bar) + + assert "progress_bar_type" in captured_kwargs + + @pytest.mark.single class TestToGBQIntegrationWithServiceAccountKeyPath: @classmethod From db725143f203a7ca6b271a7f0adb5fdfe00d5ead Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Tue, 26 Nov 2019 15:14:37 +0100 Subject: [PATCH 3/9] better doc --- pandas/io/gbq.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index 3dd5e684a83e5..021f71864ebb6 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -152,8 +152,8 @@ def read_gbq( Use the :func:`tqdm.tqdm_gui` function to display a progress bar as a graphical dialog box. - This feature requires version 0.12.0 or later of the ``pandas-gbq`` - package. It also requires the ``tqdm`` package. + Note that his feature requires version 0.12.0 or later of the + ``pandas-gbq`` package. And it requires the ``tqdm`` package. .. versionadded:: 1.0.0 From ef2960d8bca7c3d2aeddb6d8b77264239d899423 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Tue, 26 Nov 2019 15:39:35 +0100 Subject: [PATCH 4/9] fix doc failure --- pandas/io/gbq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index 021f71864ebb6..bbfef7d1b91cd 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -135,7 +135,7 @@ def read_gbq( Deprecated in pandas-gbq version 0.4.0. Use the `logging module to adjust verbosity instead `__. - progress_bar_type (Optional[str]): + progress_bar_type : Optional, str If set, use the `tqdm `_ library to display a progress bar while the data downloads. Install the ``tqdm`` package to use this feature. From e18430585c84f0061622e99bfa3942ddce4b6fe2 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Wed, 27 Nov 2019 08:57:06 +0100 Subject: [PATCH 5/9] Add whatsnew note --- doc/source/whatsnew/v1.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index db23bfdc8a5bd..6e1cf9ab66201 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -600,6 +600,7 @@ I/O - Bug in :meth:`DataFrame.to_clipboard` which did not work reliably in ipython (:issue:`22707`) - Bug in :func:`read_json` where default encoding was not set to ``utf-8`` (:issue:`29565`) - Bug in :class:`PythonParser` where str and bytes were being mixed when dealing with the decimal field (:issue:`29650`) +- :meth:`read_gbq` now accepts ``progress_bar_type`` to display progress bar while the data downloads. (:issue:`29857`) - Plotting From 1464b599c0a1d411094fadb661a71eaccd9f92d5 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Wed, 27 Nov 2019 15:07:40 +0100 Subject: [PATCH 6/9] try fix doc error --- pandas/io/gbq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index bbfef7d1b91cd..16c4ecba324f7 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -136,7 +136,7 @@ def read_gbq( adjust verbosity instead `__. progress_bar_type : Optional, str - If set, use the `tqdm `_ library to + If set, use the `tqdm `__ library to display a progress bar while the data downloads. Install the ``tqdm`` package to use this feature. Possible values of ``progress_bar_type`` include: From 01207a8cd0d303ec2d3e78fbe1fb98c86e9a837b Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Wed, 27 Nov 2019 20:18:09 +0100 Subject: [PATCH 7/9] try find where the doc error is --- pandas/io/gbq.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index 16c4ecba324f7..79823476d9a36 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -135,27 +135,6 @@ def read_gbq( Deprecated in pandas-gbq version 0.4.0. Use the `logging module to adjust verbosity instead `__. - progress_bar_type : Optional, str - If set, use the `tqdm `__ library to - display a progress bar while the data downloads. Install the - ``tqdm`` package to use this feature. - Possible values of ``progress_bar_type`` include: - ``None`` - No progress bar. - ``'tqdm'`` - Use the :func:`tqdm.tqdm` function to print a progress bar - to :data:`sys.stderr`. - ``'tqdm_notebook'`` - Use the :func:`tqdm.tqdm_notebook` function to display a - progress bar as a Jupyter notebook widget. - ``'tqdm_gui'`` - Use the :func:`tqdm.tqdm_gui` function to display a - progress bar as a graphical dialog box. - - Note that his feature requires version 0.12.0 or later of the - ``pandas-gbq`` package. And it requires the ``tqdm`` package. - - .. versionadded:: 1.0.0 Returns ------- From 9020a06daf6bb343f9941a654f2951246de70734 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Wed, 27 Nov 2019 21:00:24 +0100 Subject: [PATCH 8/9] add corrected doc --- pandas/io/gbq.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index 79823476d9a36..f3385f853dfb7 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -135,6 +135,29 @@ def read_gbq( Deprecated in pandas-gbq version 0.4.0. Use the `logging module to adjust verbosity instead `__. + progress_bar_type : Optional, str + If set, use the `tqdm `__ library to + display a progress bar while the data downloads. Install the + ``tqdm`` package to use this feature. + + Possible values of ``progress_bar_type`` include: + + ``None`` + No progress bar. + ``'tqdm'`` + Use the :func:`tqdm.tqdm` function to print a progress bar + to :data:`sys.stderr`. + ``'tqdm_notebook'`` + Use the :func:`tqdm.tqdm_notebook` function to display a + progress bar as a Jupyter notebook widget. + ``'tqdm_gui'`` + Use the :func:`tqdm.tqdm_gui` function to display a + progress bar as a graphical dialog box. + + Note that his feature requires version 0.12.0 or later of the + ``pandas-gbq`` package. And it requires the ``tqdm`` package. + + .. versionadded:: 1.0.0 Returns ------- From 2ff5903b16ff45cfada49a5c53fed67bb7ade384 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Mon, 2 Dec 2019 09:55:56 +0100 Subject: [PATCH 9/9] code change based on reviews --- pandas/io/gbq.py | 8 +++++--- pandas/tests/io/test_gbq.py | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index f3385f853dfb7..9fac7a52b370d 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -27,7 +27,7 @@ def read_gbq( use_bqstorage_api=None, private_key=None, verbose=None, - progress_bar_type="tqdm", + progress_bar_type=None, ): """ Load data from Google BigQuery. @@ -155,7 +155,8 @@ def read_gbq( progress bar as a graphical dialog box. Note that his feature requires version 0.12.0 or later of the - ``pandas-gbq`` package. And it requires the ``tqdm`` package. + ``pandas-gbq`` package. And it requires the ``tqdm`` package. Slightly + different than ``pandas-gbq``, here the default is ``None``. .. versionadded:: 1.0.0 @@ -177,7 +178,8 @@ def read_gbq( if use_bqstorage_api is not None: kwargs["use_bqstorage_api"] = use_bqstorage_api - kwargs["progress_bar_type"] = progress_bar_type + if progress_bar_type is not None: + kwargs["progress_bar_type"] = progress_bar_type # END: new kwargs # START: deprecated kwargs. Don't populate unless explicitly set. diff --git a/pandas/tests/io/test_gbq.py b/pandas/tests/io/test_gbq.py index 42596b98912cf..75c80bb0b8025 100644 --- a/pandas/tests/io/test_gbq.py +++ b/pandas/tests/io/test_gbq.py @@ -156,7 +156,10 @@ def mock_read_gbq(sql, **kwargs): monkeypatch.setattr("pandas_gbq.read_gbq", mock_read_gbq) pd.read_gbq("SELECT 1", progress_bar_type=progress_bar) - assert "progress_bar_type" in captured_kwargs + if progress_bar: + assert "progress_bar_type" in captured_kwargs + else: + assert "progress_bar_type" not in captured_kwargs @pytest.mark.single