Skip to content

TST: Fixing broken doctests in pandas/core #42598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,44 +107,20 @@ fi
### DOCTESTS ###
if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then

MSG='Doctests for individual files' ; echo $MSG
pytest -q --doctest-modules \
pandas/core/accessor.py \
pandas/core/aggregation.py \
pandas/core/algorithms.py \
pandas/core/base.py \
pandas/core/construction.py \
pandas/core/frame.py \
pandas/core/generic.py \
pandas/core/indexers.py \
pandas/core/nanops.py \
pandas/core/series.py \
pandas/io/sql.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests for directories' ; echo $MSG
pytest -q --doctest-modules \
MSG='Doctests' ; echo $MSG
python -m pytest --doctest-modules \
pandas/_libs/ \
pandas/api/ \
pandas/arrays/ \
pandas/compat/ \
pandas/core/array_algos/ \
pandas/core/arrays/ \
pandas/core/computation/ \
pandas/core/dtypes/ \
pandas/core/groupby/ \
pandas/core/indexes/ \
pandas/core/ops/ \
pandas/core/reshape/ \
pandas/core/strings/ \
pandas/core/tools/ \
pandas/core/window/ \
pandas/core \
pandas/errors/ \
pandas/io/clipboard/ \
pandas/io/json/ \
pandas/io/excel/ \
pandas/io/parsers/ \
pandas/io/sas/ \
pandas/io/sql.py \
pandas/tseries/
RET=$(($RET + $?)) ; echo $MSG "DONE"

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def allows_duplicate_labels(self) -> bool:
Examples
--------
>>> df = pd.DataFrame({"A": [1, 2]}, index=['a', 'a'])
>>> df.allows_duplicate_labels
>>> df.flags.allows_duplicate_labels
True
>>> df.allows_duplicate_labels = False
>>> df.flags.allows_duplicate_labels = False
Traceback (most recent call last):
...
pandas.errors.DuplicateLabelError: Index has duplicates.
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,14 @@ def dataclasses_to_dicts(data):
Examples
--------
>>> from dataclasses import dataclass
>>> @dataclass
>>> class Point:
... class Point:
... x: int
... y: int
>>> dataclasses_to_dicts([Point(1,2), Point(2,3)])
[{"x":1,"y":2},{"x":2,"y":3}]
>>> dataclasses_to_dicts([Point(1, 2), Point(2, 3)])
[{'x': 1, 'y': 2}, {'x': 2, 'y': 3}]
"""
from dataclasses import asdict
Expand Down
34 changes: 23 additions & 11 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ def pipe(
"""
Examples
--------
>>> s = pd.Series([1,2,3,4,5],
index=pd.date_range('20130101', periods=5,freq='s'))
>>> s = pd.Series([1, 2, 3, 4, 5],
... index=pd.date_range('20130101', periods=5, freq='s'))
>>> s
2013-01-01 00:00:00 1
2013-01-01 00:00:01 2
2013-01-01 00:00:02 3
Expand All @@ -296,27 +297,25 @@ def pipe(
Freq: S, dtype: int64

>>> r = s.resample('2s')
DatetimeIndexResampler [freq=<2 * Seconds>, axis=0, closed=left,
label=left, convention=start]

>>> r.agg(np.sum)
2013-01-01 00:00:00 3
2013-01-01 00:00:02 7
2013-01-01 00:00:04 5
Freq: 2S, dtype: int64

>>> r.agg(['sum','mean','max'])
>>> r.agg(['sum', 'mean', 'max'])
sum mean max
2013-01-01 00:00:00 3 1.5 2
2013-01-01 00:00:02 7 3.5 4
2013-01-01 00:00:04 5 5.0 5

>>> r.agg({'result' : lambda x: x.mean() / x.std(),
'total' : np.sum})
total result
2013-01-01 00:00:00 3 2.121320
2013-01-01 00:00:02 7 4.949747
2013-01-01 00:00:04 5 NaN
>>> r.agg({'result': lambda x: x.mean() / x.std(),
... 'total': np.sum})
result total
2013-01-01 00:00:00 2.121320 3
2013-01-01 00:00:02 4.949747 7
2013-01-01 00:00:04 NaN 5
"""
)

Expand Down Expand Up @@ -357,7 +356,20 @@ def transform(self, arg, *args, **kwargs):

Examples
--------
>>> s = pd.Series([1, 2],
... index=pd.date_range('20180101',
... periods=2,
... freq='1h'))
>>> s
2018-01-01 00:00:00 1
2018-01-01 01:00:00 2
Freq: H, dtype: int64

>>> resampled = s.resample('15min')
>>> resampled.transform(lambda x: (x - x.mean()) / x.std())
2018-01-01 00:00:00 NaN
2018-01-01 01:00:00 NaN
Freq: H, dtype: float64
"""
return self._selected_obj.groupby(self.groupby).transform(arg, *args, **kwargs)

Expand Down