From 1fe7aa8da10c00d563a2967480f3a8a3e376de51 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Thu, 8 Nov 2018 00:19:21 +0000 Subject: [PATCH 1/2] WIP: Adding first docstrings checks to the CI --- ci/code_checks.sh | 11 +++++++++-- pandas/core/frame.py | 38 +++++++++++++++++++++----------------- pandas/core/generic.py | 3 +-- pandas/core/panel.py | 16 ++++++++-------- pandas/core/series.py | 1 - 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 330901ba56fbd..561cf43bebedd 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -16,7 +16,7 @@ echo "inside $0" [[ $LINT ]] || { echo "NOT Linting. To lint use: LINT=true $0 $1"; exit 0; } -[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "doctests" ]] || { echo "Unknown command $1. Usage: $0 [lint|patterns|doctests]"; exit 9999; } +[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "docstrings" ]] || { echo "Unknown command $1. Usage: $0 [lint|patterns|docstrings]"; exit 9999; } source activate pandas RET=0 @@ -126,9 +126,11 @@ if mods: fi -### DOCTESTS ### +### DOCSTRINGS ### if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then + # Doctests + MSG='Doctests frame.py' ; echo $MSG pytest -q --doctest-modules pandas/core/frame.py \ -k"-axes -combine -itertuples -join -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack -to_stata" @@ -160,6 +162,11 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then -k"-from_arrays -from_breaks -from_intervals -from_tuples -get_loc -set_closed -to_tuples -interval_range" RET=$(($RET + $?)) ; echo $MSG "DONE" + # Validate docstrings + MSG='Validate docstrings (SS04, EX04)' ; echo $MSG + scripts/validate_docstrings.py --errors=SS04,EX04 + RET=$(($RET + $?)) ; echo $MSG "DONE" + fi exit $RET diff --git a/pandas/core/frame.py b/pandas/core/frame.py index eff75938b1181..1a7ffc081ae9f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -864,12 +864,17 @@ def iterrows(self): data types, the iterator returns a copy and not a view, and writing to it will have no effect. - Returns - ------- + Yields + ------ + index : label or tuple of label + The index of the row. A tuple for a `MultiIndex`. + data : Series + The data of the row as a Series. + it : generator A generator that iterates over the rows of the frame. - See also + See Also -------- itertuples : Iterate over DataFrame rows as namedtuples of the values. iteritems : Iterate over (column name, Series) pairs. @@ -3940,6 +3945,10 @@ def set_index(self, keys, drop=True, append=False, inplace=False, necessary. Setting to False will improve the performance of this method + Returns + ------- + DataFrame + Examples -------- >>> df = pd.DataFrame({'month': [1, 4, 7, 10], @@ -3980,10 +3989,6 @@ def set_index(self, keys, drop=True, append=False, inplace=False, 2 2014 4 40 3 2013 7 84 4 2014 10 31 - - Returns - ------- - dataframe : DataFrame """ inplace = validate_bool_kwarg(inplace, 'inplace') if not isinstance(keys, list): @@ -6683,6 +6688,15 @@ def round(self, decimals=0, *args, **kwargs): of `decimals` which are not columns of the input will be ignored. + Returns + ------- + DataFrame + + See Also + -------- + numpy.around + Series.round + Examples -------- >>> df = pd.DataFrame(np.random.random([3, 3]), @@ -6708,15 +6722,6 @@ def round(self, decimals=0, *args, **kwargs): first 0.0 1 0.17 second 0.0 1 0.58 third 0.9 0 0.49 - - Returns - ------- - DataFrame object - - See Also - -------- - numpy.around - Series.round """ from pandas.core.reshape.concat import concat @@ -6782,7 +6787,6 @@ def corr(self, method='pearson', min_periods=1): Examples -------- - >>> import numpy as np >>> histogram_intersection = lambda a, b: np.minimum(a, b ... ).sum().round(decimals=1) >>> df = pd.DataFrame([(.2, .3), (.0, .6), (.6, .0), (.2, .1)], diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 396b092a286c1..c922a2bf66762 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9622,8 +9622,7 @@ def nanptp(values, axis=0, skipna=True): cls.ptp = _make_stat_function( cls, 'ptp', name, name2, axis_descr, - """ - Returns the difference between the maximum value and the + """Returns the difference between the maximum value and the minimum value in the object. This is the equivalent of the ``numpy.ndarray`` method ``ptp``. diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 72b014b018735..f298b3aa3d989 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -106,14 +106,14 @@ def panel_index(time, panels, names=None): class Panel(NDFrame): """ - Represents wide format panel data, stored as 3-dimensional array - - .. deprecated:: 0.20.0 - The recommended way to represent 3-D data are with a MultiIndex on a - DataFrame via the :attr:`~Panel.to_frame()` method or with the - `xarray package `__. - Pandas provides a :attr:`~Panel.to_xarray()` method to automate this - conversion. + Represents wide format panel data, stored as 3-dimensional array. + + .. deprecated:: 0.20.0 + The recommended way to represent 3-D data are with a MultiIndex on a + DataFrame via the :attr:`~Panel.to_frame()` method or with the + `xarray package `__. + Pandas provides a :attr:`~Panel.to_xarray()` method to automate this + conversion. Parameters ---------- diff --git a/pandas/core/series.py b/pandas/core/series.py index 6971b0b0c78e0..6de0d5ceb9a6e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1913,7 +1913,6 @@ def corr(self, other, method='pearson', min_periods=None): Examples -------- - >>> import numpy as np >>> histogram_intersection = lambda a, b: np.minimum(a, b ... ).sum().round(decimals=1) >>> s1 = pd.Series([.2, .0, .6, .2]) From 9047183365581bc1c59614ea408b1aa605f5a053 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sat, 10 Nov 2018 22:24:26 +0000 Subject: [PATCH 2/2] Keep the fixing the validate docstring errors, but not adding the validation at this point, as this time outs on travis, and I'll better add it to azure later --- ci/code_checks.sh | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index ff3862a48688e..eba96f0c6c2fc 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -16,7 +16,7 @@ echo "inside $0" [[ $LINT ]] || { echo "NOT Linting. To lint use: LINT=true $0 $1"; exit 0; } -[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "docstrings" ]] || { echo "Unknown command $1. Usage: $0 [lint|patterns|docstrings]"; exit 9999; } +[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "doctests" ]] || { echo "Unknown command $1. Usage: $0 [lint|patterns|doctests]"; exit 9999; } source activate pandas RET=0 @@ -136,11 +136,9 @@ if mods: fi -### DOCSTRINGS ### +### DOCTESTS ### if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then - # Doctests - MSG='Doctests frame.py' ; echo $MSG pytest -q --doctest-modules pandas/core/frame.py \ -k"-axes -combine -itertuples -join -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack -to_stata" @@ -172,11 +170,6 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then -k"-from_arrays -from_breaks -from_intervals -from_tuples -get_loc -set_closed -to_tuples -interval_range" RET=$(($RET + $?)) ; echo $MSG "DONE" - # Validate docstrings - MSG='Validate docstrings (SS04, EX04)' ; echo $MSG - scripts/validate_docstrings.py --errors=SS04,EX04 - RET=$(($RET + $?)) ; echo $MSG "DONE" - fi exit $RET