From d3bb96bc8144875af50012e0346101a88f164c85 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 20 Dec 2021 19:46:17 -0800 Subject: [PATCH 1/5] DOC: Enable doctests for _config, _testing, misc files --- ci/code_checks.sh | 8 +++++++- pandas/_config/config.py | 2 +- pandas/_testing/__init__.py | 2 +- pandas/_testing/_io.py | 4 ++-- pandas/_testing/asserters.py | 9 ++++----- pandas/_testing/contexts.py | 6 +++--- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 6335eb4b14007..f1d7fc7a86bfa 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -66,7 +66,9 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then MSG='Doctests' ; echo $MSG python -m pytest --doctest-modules \ + pandas/_config/ \ pandas/_libs/ \ + pandas/_testing/ \ pandas/api/ \ pandas/arrays/ \ pandas/compat/ \ @@ -81,7 +83,11 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pandas/io/formats/format.py \ pandas/io/formats/style.py \ pandas/io/stata.py \ - pandas/tseries/ + pandas/tseries/ \ + pandas/_typing.py \ + pandas/_version.py \ + pandas/confest.py \ + pandas/testing.py \ RET=$(($RET + $?)) ; echo $MSG "DONE" MSG='Cython Doctests' ; echo $MSG diff --git a/pandas/_config/config.py b/pandas/_config/config.py index d8b1829840a4d..5a0f58266c203 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -411,7 +411,7 @@ class option_context(ContextDecorator): Examples -------- >>> with option_context('display.max_rows', 10, 'display.max_columns', 5): - ... ... + ... pass """ def __init__(self, *args): diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index 66503ac81b4d1..5154626dc3c7c 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -431,7 +431,7 @@ def _make_timeseries(start="2000-01-01", end="2000-12-31", freq="1D", seed=None) Examples -------- - >>> _make_timeseries() + >>> _make_timeseries() # doctest: +SKIP id name x y timestamp 2000-01-01 982 Frank 0.031261 0.986727 diff --git a/pandas/_testing/_io.py b/pandas/_testing/_io.py index 2c8e1b0daaeaa..8fe78fdd499ae 100644 --- a/pandas/_testing/_io.py +++ b/pandas/_testing/_io.py @@ -167,7 +167,7 @@ def network( ... def test_network(): ... with pd.io.common.urlopen("rabbit://bonanza.com"): ... pass - >>> test_network() + >>> test_network() # doctest: +SKIP Traceback ... URLError: @@ -189,7 +189,7 @@ def network( ... def test_something(): ... print("I ran!") ... raise ValueError("Failure") - >>> test_something() + >>> test_something() # doctest: +SKIP Traceback (most recent call last): ... diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 08f92698ed9a0..d59ad72d74d73 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -193,16 +193,15 @@ def _get_tol_from_less_precise(check_less_precise: bool | int) -> float: -------- >>> # Using check_less_precise as a bool: >>> _get_tol_from_less_precise(False) - 0.5e-5 + 5e-06 >>> _get_tol_from_less_precise(True) - 0.5e-3 + 0.0005 >>> # Using check_less_precise as an int representing the decimal >>> # tolerance intended: >>> _get_tol_from_less_precise(2) - 0.5e-2 + 0.005 >>> _get_tol_from_less_precise(8) - 0.5e-8 - + 5e-09 """ if isinstance(check_less_precise, bool): if check_less_precise: diff --git a/pandas/_testing/contexts.py b/pandas/_testing/contexts.py index db35b2e7b4cab..aff3e9e5471de 100644 --- a/pandas/_testing/contexts.py +++ b/pandas/_testing/contexts.py @@ -54,13 +54,13 @@ def set_timezone(tz: str): -------- >>> from datetime import datetime >>> from dateutil.tz import tzlocal - >>> tzlocal().tzname(datetime.now()) + >>> tzlocal().tzname(datetime(2021, 1, 1)) # doctest: +SKIP 'IST' >>> with set_timezone('US/Eastern'): - ... tzlocal().tzname(datetime.now()) + ... tzlocal().tzname(datetime(2021, 1, 1)) ... - 'EDT' + 'EST' """ import os import time From 54fe14e3debc7ebde21bb6641989fc3b491cf798 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 20 Dec 2021 20:02:18 -0800 Subject: [PATCH 2/5] Add util also --- pandas/util/_decorators.py | 12 ++++++------ pandas/util/_validators.py | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index a936b8d1f585c..39a729bc51f35 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -122,19 +122,19 @@ def deprecate_kwarg( >>> f(columns='should work ok') should work ok - >>> f(cols='should raise warning') + >>> f(cols='should raise warning') # doctest: +SKIP FutureWarning: cols is deprecated, use columns instead warnings.warn(msg, FutureWarning) should raise warning - >>> f(cols='should error', columns="can\'t pass do both") + >>> f(cols='should error', columns="can\'t pass do both") # doctest: +SKIP TypeError: Can only specify 'cols' or 'columns', not both >>> @deprecate_kwarg('old', 'new', {'yes': True, 'no': False}) ... def f(new=False): ... print('yes!' if new else 'no!') ... - >>> f(old='yes') + >>> f(old='yes') # doctest: +SKIP FutureWarning: old='yes' is deprecated, use new=True instead warnings.warn(msg, FutureWarning) yes! @@ -145,14 +145,14 @@ def deprecate_kwarg( ... def f(cols='', another_param=''): ... print(cols) ... - >>> f(cols='should raise warning') + >>> f(cols='should raise warning') # doctest: +SKIP FutureWarning: the 'cols' keyword is deprecated and will be removed in a future version please takes steps to stop use of 'cols' should raise warning - >>> f(another_param='should not raise warning') + >>> f(another_param='should not raise warning') # doctest: +SKIP should not raise warning - >>> f(cols='should raise warning', another_param='') + >>> f(cols='should raise warning', another_param='') # doctest: +SKIP FutureWarning: the 'cols' keyword is deprecated and will be removed in a future version please takes steps to stop use of 'cols' should raise warning diff --git a/pandas/util/_validators.py b/pandas/util/_validators.py index ee54b1b2074cb..8e3de9404fbee 100644 --- a/pandas/util/_validators.py +++ b/pandas/util/_validators.py @@ -281,14 +281,15 @@ def validate_axis_style_args(data, args, kwargs, arg_name, method_name): Examples -------- - >>> df._validate_axis_style_args((str.upper,), {'columns': id}, - ... 'mapper', 'rename') - {'columns': , 'index': } + >>> df = pd.DataFrame(range(2)) + >>> validate_axis_style_args(df, (str.upper,), {'columns': id}, + ... 'mapper', 'rename') + {'columns': , 'index': } This emits a warning - >>> df._validate_axis_style_args((str.upper, id), {}, - ... 'mapper', 'rename') - {'columns': , 'index': } + >>> validate_axis_style_args(df, (str.upper, id), {}, + ... 'mapper', 'rename') + {'index': , 'columns': } """ # TODO: Change to keyword-only args and remove all this From 04a6279d14be2901cc0428621b4df2903fd8580e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 20 Dec 2021 20:26:05 -0800 Subject: [PATCH 3/5] Also fix pandas/io --- ci/code_checks.sh | 10 +--------- pandas/io/formats/style_render.py | 5 +++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index f1d7fc7a86bfa..95503ddbcc3fa 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -74,15 +74,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pandas/compat/ \ pandas/core \ pandas/errors/ \ - pandas/io/clipboard/ \ - pandas/io/json/ \ - pandas/io/excel/ \ - pandas/io/parsers/ \ - pandas/io/sas/ \ - pandas/io/sql.py \ - pandas/io/formats/format.py \ - pandas/io/formats/style.py \ - pandas/io/stata.py \ + pandas/io/ \ pandas/tseries/ \ pandas/_typing.py \ pandas/_version.py \ diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index de475d145f3a0..dcb1f9a2a70dc 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -1062,7 +1062,7 @@ def format_index( -------- Using ``na_rep`` and ``precision`` with the default ``formatter`` - >>> df = pd.DataFrame([[1, 2, 3]], columns=[2.0, np.nan, 4.0]]) + >>> df = pd.DataFrame([[1, 2, 3]], columns=[2.0, np.nan, 4.0]) >>> df.style.format_index(axis=1, na_rep='MISS', precision=3) # doctest: +SKIP 2.000 MISS 4.000 0 1 2 3 @@ -1096,6 +1096,7 @@ def format_index( >>> df = pd.DataFrame([[1, 2, 3]], columns=['"A"', 'A&B', None]) >>> s = df.style.format_index('$ {0}', axis=1, escape="html", na_rep="NA") + ... # doctest: +SKIP $ "A" $ A&B NA @@ -1811,7 +1812,7 @@ def _parse_latex_header_span( Examples -------- - >>> cell = {'display_value':'text', 'attributes': 'colspan="3"'} + >>> cell = {'cellstyle': '', 'display_value':'text', 'attributes': 'colspan="3"'} >>> _parse_latex_header_span(cell, 't', 'c') '\\multicolumn{3}{c}{text}' """ From b7dcc344ed5ccf09a0cfd80c0702f8636b633c52 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 20 Dec 2021 20:54:08 -0800 Subject: [PATCH 4/5] Add util to code_check --- ci/code_checks.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 95503ddbcc3fa..22221ca2b58ef 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -76,6 +76,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pandas/errors/ \ pandas/io/ \ pandas/tseries/ \ + pandas/util/ \ pandas/_typing.py \ pandas/_version.py \ pandas/confest.py \ From c147dca732d735d2e62ec5cb57cd858640a003b7 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 20 Dec 2021 22:24:15 -0800 Subject: [PATCH 5/5] Fix paths --- ci/code_checks.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 22221ca2b58ef..64c8368e06417 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -79,8 +79,8 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pandas/util/ \ pandas/_typing.py \ pandas/_version.py \ - pandas/confest.py \ - pandas/testing.py \ + pandas/conftest.py \ + pandas/testing.py RET=$(($RET + $?)) ; echo $MSG "DONE" MSG='Cython Doctests' ; echo $MSG