Skip to content

Commit 425f42d

Browse files
datapythonistafeefladder
authored andcommitted
TST: Fixing broken doctests in pandas/core (pandas-dev#42598)
1 parent 2ff4bf2 commit 425f42d

File tree

4 files changed

+33
-44
lines changed

4 files changed

+33
-44
lines changed

ci/code_checks.sh

+4-28
Original file line numberDiff line numberDiff line change
@@ -107,44 +107,20 @@ fi
107107
### DOCTESTS ###
108108
if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
109109

110-
MSG='Doctests for individual files' ; echo $MSG
111-
pytest -q --doctest-modules \
112-
pandas/core/accessor.py \
113-
pandas/core/aggregation.py \
114-
pandas/core/algorithms.py \
115-
pandas/core/base.py \
116-
pandas/core/construction.py \
117-
pandas/core/frame.py \
118-
pandas/core/generic.py \
119-
pandas/core/indexers.py \
120-
pandas/core/nanops.py \
121-
pandas/core/series.py \
122-
pandas/io/sql.py
123-
RET=$(($RET + $?)) ; echo $MSG "DONE"
124-
125-
MSG='Doctests for directories' ; echo $MSG
126-
pytest -q --doctest-modules \
110+
MSG='Doctests' ; echo $MSG
111+
python -m pytest --doctest-modules \
127112
pandas/_libs/ \
128113
pandas/api/ \
129114
pandas/arrays/ \
130115
pandas/compat/ \
131-
pandas/core/array_algos/ \
132-
pandas/core/arrays/ \
133-
pandas/core/computation/ \
134-
pandas/core/dtypes/ \
135-
pandas/core/groupby/ \
136-
pandas/core/indexes/ \
137-
pandas/core/ops/ \
138-
pandas/core/reshape/ \
139-
pandas/core/strings/ \
140-
pandas/core/tools/ \
141-
pandas/core/window/ \
116+
pandas/core \
142117
pandas/errors/ \
143118
pandas/io/clipboard/ \
144119
pandas/io/json/ \
145120
pandas/io/excel/ \
146121
pandas/io/parsers/ \
147122
pandas/io/sas/ \
123+
pandas/io/sql.py \
148124
pandas/tseries/
149125
RET=$(($RET + $?)) ; echo $MSG "DONE"
150126

pandas/core/flags.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def allows_duplicate_labels(self) -> bool:
6868
Examples
6969
--------
7070
>>> df = pd.DataFrame({"A": [1, 2]}, index=['a', 'a'])
71-
>>> df.allows_duplicate_labels
71+
>>> df.flags.allows_duplicate_labels
7272
True
73-
>>> df.allows_duplicate_labels = False
73+
>>> df.flags.allows_duplicate_labels = False
7474
Traceback (most recent call last):
7575
...
7676
pandas.errors.DuplicateLabelError: Index has duplicates.

pandas/core/internals/construction.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,14 @@ def dataclasses_to_dicts(data):
712712
713713
Examples
714714
--------
715+
>>> from dataclasses import dataclass
715716
>>> @dataclass
716-
>>> class Point:
717+
... class Point:
717718
... x: int
718719
... y: int
719720
720-
>>> dataclasses_to_dicts([Point(1,2), Point(2,3)])
721-
[{"x":1,"y":2},{"x":2,"y":3}]
721+
>>> dataclasses_to_dicts([Point(1, 2), Point(2, 3)])
722+
[{'x': 1, 'y': 2}, {'x': 2, 'y': 3}]
722723
723724
"""
724725
from dataclasses import asdict

pandas/core/resample.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ def pipe(
286286
"""
287287
Examples
288288
--------
289-
>>> s = pd.Series([1,2,3,4,5],
290-
index=pd.date_range('20130101', periods=5,freq='s'))
289+
>>> s = pd.Series([1, 2, 3, 4, 5],
290+
... index=pd.date_range('20130101', periods=5, freq='s'))
291+
>>> s
291292
2013-01-01 00:00:00 1
292293
2013-01-01 00:00:01 2
293294
2013-01-01 00:00:02 3
@@ -296,27 +297,25 @@ def pipe(
296297
Freq: S, dtype: int64
297298
298299
>>> r = s.resample('2s')
299-
DatetimeIndexResampler [freq=<2 * Seconds>, axis=0, closed=left,
300-
label=left, convention=start]
301300
302301
>>> r.agg(np.sum)
303302
2013-01-01 00:00:00 3
304303
2013-01-01 00:00:02 7
305304
2013-01-01 00:00:04 5
306305
Freq: 2S, dtype: int64
307306
308-
>>> r.agg(['sum','mean','max'])
307+
>>> r.agg(['sum', 'mean', 'max'])
309308
sum mean max
310309
2013-01-01 00:00:00 3 1.5 2
311310
2013-01-01 00:00:02 7 3.5 4
312311
2013-01-01 00:00:04 5 5.0 5
313312
314-
>>> r.agg({'result' : lambda x: x.mean() / x.std(),
315-
'total' : np.sum})
316-
total result
317-
2013-01-01 00:00:00 3 2.121320
318-
2013-01-01 00:00:02 7 4.949747
319-
2013-01-01 00:00:04 5 NaN
313+
>>> r.agg({'result': lambda x: x.mean() / x.std(),
314+
... 'total': np.sum})
315+
result total
316+
2013-01-01 00:00:00 2.121320 3
317+
2013-01-01 00:00:02 4.949747 7
318+
2013-01-01 00:00:04 NaN 5
320319
"""
321320
)
322321

@@ -357,7 +356,20 @@ def transform(self, arg, *args, **kwargs):
357356
358357
Examples
359358
--------
359+
>>> s = pd.Series([1, 2],
360+
... index=pd.date_range('20180101',
361+
... periods=2,
362+
... freq='1h'))
363+
>>> s
364+
2018-01-01 00:00:00 1
365+
2018-01-01 01:00:00 2
366+
Freq: H, dtype: int64
367+
368+
>>> resampled = s.resample('15min')
360369
>>> resampled.transform(lambda x: (x - x.mean()) / x.std())
370+
2018-01-01 00:00:00 NaN
371+
2018-01-01 01:00:00 NaN
372+
Freq: H, dtype: float64
361373
"""
362374
return self._selected_obj.groupby(self.groupby).transform(arg, *args, **kwargs)
363375

0 commit comments

Comments
 (0)