Skip to content

Commit 2cc9ab3

Browse files
authored
DOC: Enable doctests for _config, _testing, utils, io, misc files (#44990)
* DOC: Enable doctests for _config, _testing, misc files * Add util also * Also fix pandas/io * Add util to code_check * Fix paths
1 parent e86cad9 commit 2cc9ab3

File tree

9 files changed

+36
-36
lines changed

9 files changed

+36
-36
lines changed

ci/code_checks.sh

+9-10
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,21 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
6666

6767
MSG='Doctests' ; echo $MSG
6868
python -m pytest --doctest-modules \
69+
pandas/_config/ \
6970
pandas/_libs/ \
71+
pandas/_testing/ \
7072
pandas/api/ \
7173
pandas/arrays/ \
7274
pandas/compat/ \
7375
pandas/core \
7476
pandas/errors/ \
75-
pandas/io/clipboard/ \
76-
pandas/io/json/ \
77-
pandas/io/excel/ \
78-
pandas/io/parsers/ \
79-
pandas/io/sas/ \
80-
pandas/io/sql.py \
81-
pandas/io/formats/format.py \
82-
pandas/io/formats/style.py \
83-
pandas/io/stata.py \
84-
pandas/tseries/
77+
pandas/io/ \
78+
pandas/tseries/ \
79+
pandas/util/ \
80+
pandas/_typing.py \
81+
pandas/_version.py \
82+
pandas/conftest.py \
83+
pandas/testing.py
8584
RET=$(($RET + $?)) ; echo $MSG "DONE"
8685

8786
MSG='Cython Doctests' ; echo $MSG

pandas/_config/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class option_context(ContextDecorator):
411411
Examples
412412
--------
413413
>>> with option_context('display.max_rows', 10, 'display.max_columns', 5):
414-
... ...
414+
... pass
415415
"""
416416

417417
def __init__(self, *args):

pandas/_testing/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def _make_timeseries(start="2000-01-01", end="2000-12-31", freq="1D", seed=None)
431431
432432
Examples
433433
--------
434-
>>> _make_timeseries()
434+
>>> _make_timeseries() # doctest: +SKIP
435435
id name x y
436436
timestamp
437437
2000-01-01 982 Frank 0.031261 0.986727

pandas/_testing/_io.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def network(
167167
... def test_network():
168168
... with pd.io.common.urlopen("rabbit://bonanza.com"):
169169
... pass
170-
>>> test_network()
170+
>>> test_network() # doctest: +SKIP
171171
Traceback
172172
...
173173
URLError: <urlopen error unknown url type: rabbit>
@@ -189,7 +189,7 @@ def network(
189189
... def test_something():
190190
... print("I ran!")
191191
... raise ValueError("Failure")
192-
>>> test_something()
192+
>>> test_something() # doctest: +SKIP
193193
Traceback (most recent call last):
194194
...
195195

pandas/_testing/asserters.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,15 @@ def _get_tol_from_less_precise(check_less_precise: bool | int) -> float:
193193
--------
194194
>>> # Using check_less_precise as a bool:
195195
>>> _get_tol_from_less_precise(False)
196-
0.5e-5
196+
5e-06
197197
>>> _get_tol_from_less_precise(True)
198-
0.5e-3
198+
0.0005
199199
>>> # Using check_less_precise as an int representing the decimal
200200
>>> # tolerance intended:
201201
>>> _get_tol_from_less_precise(2)
202-
0.5e-2
202+
0.005
203203
>>> _get_tol_from_less_precise(8)
204-
0.5e-8
205-
204+
5e-09
206205
"""
207206
if isinstance(check_less_precise, bool):
208207
if check_less_precise:

pandas/_testing/contexts.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ def set_timezone(tz: str):
5454
--------
5555
>>> from datetime import datetime
5656
>>> from dateutil.tz import tzlocal
57-
>>> tzlocal().tzname(datetime.now())
57+
>>> tzlocal().tzname(datetime(2021, 1, 1)) # doctest: +SKIP
5858
'IST'
5959
6060
>>> with set_timezone('US/Eastern'):
61-
... tzlocal().tzname(datetime.now())
61+
... tzlocal().tzname(datetime(2021, 1, 1))
6262
...
63-
'EDT'
63+
'EST'
6464
"""
6565
import os
6666
import time

pandas/io/formats/style_render.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ def format_index(
10621062
--------
10631063
Using ``na_rep`` and ``precision`` with the default ``formatter``
10641064
1065-
>>> df = pd.DataFrame([[1, 2, 3]], columns=[2.0, np.nan, 4.0]])
1065+
>>> df = pd.DataFrame([[1, 2, 3]], columns=[2.0, np.nan, 4.0])
10661066
>>> df.style.format_index(axis=1, na_rep='MISS', precision=3) # doctest: +SKIP
10671067
2.000 MISS 4.000
10681068
0 1 2 3
@@ -1096,6 +1096,7 @@ def format_index(
10961096
10971097
>>> df = pd.DataFrame([[1, 2, 3]], columns=['"A"', 'A&B', None])
10981098
>>> s = df.style.format_index('$ {0}', axis=1, escape="html", na_rep="NA")
1099+
... # doctest: +SKIP
10991100
<th .. >$ &#34;A&#34;</th>
11001101
<th .. >$ A&amp;B</th>
11011102
<th .. >NA</td>
@@ -1811,7 +1812,7 @@ def _parse_latex_header_span(
18111812
18121813
Examples
18131814
--------
1814-
>>> cell = {'display_value':'text', 'attributes': 'colspan="3"'}
1815+
>>> cell = {'cellstyle': '', 'display_value':'text', 'attributes': 'colspan="3"'}
18151816
>>> _parse_latex_header_span(cell, 't', 'c')
18161817
'\\multicolumn{3}{c}{text}'
18171818
"""

pandas/util/_decorators.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,19 @@ def deprecate_kwarg(
122122
>>> f(columns='should work ok')
123123
should work ok
124124
125-
>>> f(cols='should raise warning')
125+
>>> f(cols='should raise warning') # doctest: +SKIP
126126
FutureWarning: cols is deprecated, use columns instead
127127
warnings.warn(msg, FutureWarning)
128128
should raise warning
129129
130-
>>> f(cols='should error', columns="can\'t pass do both")
130+
>>> f(cols='should error', columns="can\'t pass do both") # doctest: +SKIP
131131
TypeError: Can only specify 'cols' or 'columns', not both
132132
133133
>>> @deprecate_kwarg('old', 'new', {'yes': True, 'no': False})
134134
... def f(new=False):
135135
... print('yes!' if new else 'no!')
136136
...
137-
>>> f(old='yes')
137+
>>> f(old='yes') # doctest: +SKIP
138138
FutureWarning: old='yes' is deprecated, use new=True instead
139139
warnings.warn(msg, FutureWarning)
140140
yes!
@@ -145,14 +145,14 @@ def deprecate_kwarg(
145145
... def f(cols='', another_param=''):
146146
... print(cols)
147147
...
148-
>>> f(cols='should raise warning')
148+
>>> f(cols='should raise warning') # doctest: +SKIP
149149
FutureWarning: the 'cols' keyword is deprecated and will be removed in a
150150
future version please takes steps to stop use of 'cols'
151151
should raise warning
152-
>>> f(another_param='should not raise warning')
152+
>>> f(another_param='should not raise warning') # doctest: +SKIP
153153
should not raise warning
154154
155-
>>> f(cols='should raise warning', another_param='')
155+
>>> f(cols='should raise warning', another_param='') # doctest: +SKIP
156156
FutureWarning: the 'cols' keyword is deprecated and will be removed in a
157157
future version please takes steps to stop use of 'cols'
158158
should raise warning

pandas/util/_validators.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,15 @@ def validate_axis_style_args(data, args, kwargs, arg_name, method_name):
281281
282282
Examples
283283
--------
284-
>>> df._validate_axis_style_args((str.upper,), {'columns': id},
285-
... 'mapper', 'rename')
286-
{'columns': <function id>, 'index': <method 'upper' of 'str' objects>}
284+
>>> df = pd.DataFrame(range(2))
285+
>>> validate_axis_style_args(df, (str.upper,), {'columns': id},
286+
... 'mapper', 'rename')
287+
{'columns': <built-in function id>, 'index': <method 'upper' of 'str' objects>}
287288
288289
This emits a warning
289-
>>> df._validate_axis_style_args((str.upper, id), {},
290-
... 'mapper', 'rename')
291-
{'columns': <function id>, 'index': <method 'upper' of 'str' objects>}
290+
>>> validate_axis_style_args(df, (str.upper, id), {},
291+
... 'mapper', 'rename')
292+
{'index': <method 'upper' of 'str' objects>, 'columns': <built-in function id>}
292293
"""
293294
# TODO: Change to keyword-only args and remove all this
294295

0 commit comments

Comments
 (0)