diff --git a/pandas/core/base.py b/pandas/core/base.py index e7c3a45a710e0..a584458c5cb58 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -291,6 +291,12 @@ def _gotitem(self, key, ndim, subset=None): raise AbstractMethodError(self) def aggregate(self, func, *args, **kwargs): + """ + :param func: + :param args: + :param kwargs: + :return: + """ raise AbstractMethodError(self) agg = aggregate @@ -1254,16 +1260,14 @@ def is_unique(self): @property def is_monotonic(self): - """ - Return boolean if values in the object are + """Return boolean if values in the object are monotonic_increasing .. versionadded:: 0.19.0 Returns ------- - is_monotonic : boolean - """ + is_monotonic : boolean""" from pandas import Index return Index(self).is_monotonic @@ -1271,16 +1275,14 @@ def is_monotonic(self): @property def is_monotonic_decreasing(self): - """ - Return boolean if values in the object are + """Return boolean if values in the object are monotonic_decreasing .. versionadded:: 0.19.0 Returns ------- - is_monotonic_decreasing : boolean - """ + is_monotonic_decreasing : boolean""" from pandas import Index return Index(self).is_monotonic_decreasing diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b9f32042924b9..c1af2ca509bce 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6030,8 +6030,7 @@ def melt(self, id_vars=None, value_vars=None, var_name=None, # Time series-related def diff(self, periods=1, axis=0): - """ - First discrete difference of element. + """First discrete difference of element. Calculates the difference of a DataFrame element compared with another element in the DataFrame (default is the element in the same column @@ -6114,8 +6113,7 @@ def diff(self, periods=1, axis=0): 2 -1.0 -1.0 -7.0 3 -1.0 -2.0 -9.0 4 -1.0 -3.0 -11.0 - 5 NaN NaN NaN - """ + 5 NaN NaN NaN""" bm_axis = self._get_block_manager_axis(axis) new_data = self._data.diff(n=periods, axis=bm_axis) return self._constructor(new_data) @@ -6880,8 +6878,7 @@ def _series_round(s, decimals): # Statistical methods, etc. def corr(self, method='pearson', min_periods=1): - """ - Compute pairwise correlation of columns, excluding NA/null values. + """Compute pairwise correlation of columns, excluding NA/null values. Parameters ---------- @@ -6911,8 +6908,7 @@ def corr(self, method='pearson', min_periods=1): >>> df.corr(method=histogram_intersection) dogs cats dogs 1.0 0.3 - cats 0.3 1.0 - """ + cats 0.3 1.0""" numeric_df = self._get_numeric_data() cols = numeric_df.columns idx = cols.copy() @@ -6955,8 +6951,7 @@ def corr(self, method='pearson', min_periods=1): return self._constructor(correl, index=idx, columns=cols) def cov(self, min_periods=None): - """ - Compute pairwise covariance of columns, excluding NA/null values. + """Compute pairwise covariance of columns, excluding NA/null values. Compute the pairwise covariance among the series of a DataFrame. The returned data frame is the `covariance matrix @@ -7045,8 +7040,7 @@ def cov(self, min_periods=None): a b c a 0.316741 NaN -0.150812 b NaN 1.248003 0.191417 - c -0.150812 0.191417 0.895202 - """ + c -0.150812 0.191417 0.895202""" numeric_df = self._get_numeric_data() cols = numeric_df.columns idx = cols.copy() @@ -7066,8 +7060,7 @@ def cov(self, min_periods=None): return self._constructor(baseCov, index=idx, columns=cols) def corrwith(self, other, axis=0, drop=False): - """ - Compute pairwise correlation between rows or columns of two DataFrame + """Compute pairwise correlation between rows or columns of two DataFrame objects. Parameters @@ -7080,8 +7073,7 @@ def corrwith(self, other, axis=0, drop=False): Returns ------- - correls : Series - """ + correls : Series""" axis = self._get_axis_number(axis) this = self._get_numeric_data() @@ -7404,8 +7396,7 @@ def nunique(self, axis=0, dropna=True): return self.apply(Series.nunique, axis=axis, dropna=dropna) def idxmin(self, axis=0, skipna=True): - """ - Return index of first occurrence of minimum over requested axis. + """Return index of first occurrence of minimum over requested axis. NA/null values are excluded. Parameters @@ -7431,8 +7422,7 @@ def idxmin(self, axis=0, skipna=True): See Also -------- - Series.idxmin - """ + Series.idxmin""" axis = self._get_axis_number(axis) indices = nanops.nanargmin(self.values, axis=axis, skipna=skipna) index = self._get_axis(axis) @@ -7440,8 +7430,7 @@ def idxmin(self, axis=0, skipna=True): return Series(result, index=self._get_agg_axis(axis)) def idxmax(self, axis=0, skipna=True): - """ - Return index of first occurrence of maximum over requested axis. + """Return index of first occurrence of maximum over requested axis. NA/null values are excluded. Parameters @@ -7467,8 +7456,7 @@ def idxmax(self, axis=0, skipna=True): See Also -------- - Series.idxmax - """ + Series.idxmax""" axis = self._get_axis_number(axis) indices = nanops.nanargmax(self.values, axis=axis, skipna=skipna) index = self._get_axis(axis) @@ -7574,8 +7562,7 @@ def f(s): def quantile(self, q=0.5, axis=0, numeric_only=True, interpolation='linear'): - """ - Return values at the given quantile over requested axis. + """Return values at the given quantile over requested axis. Parameters ---------- @@ -7640,8 +7627,7 @@ def quantile(self, q=0.5, axis=0, numeric_only=True, See Also -------- pandas.core.window.Rolling.quantile - numpy.percentile - """ + numpy.percentile""" self._check_percentile(q) data = self._get_numeric_data() if numeric_only else self diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e780c8344869f..bbe65efaa992c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3338,8 +3338,7 @@ def _take(self, indices, axis=0, is_copy=True): return result def take(self, indices, axis=0, convert=None, is_copy=True, **kwargs): - """ - Return the elements in the given *positional* indices along an axis. + """Return the elements in the given *positional* indices along an axis. This means that we are not indexing according to actual values in the index attribute of the object. We are indexing according to the @@ -3419,8 +3418,7 @@ class max_speed >>> df.take([-1, -2]) name class max_speed 1 monkey mammal NaN - 3 lion mammal 80.5 - """ + 3 lion mammal 80.5""" if convert is not None: msg = ("The 'convert' parameter is deprecated " "and will be removed in a future version.") @@ -5903,8 +5901,7 @@ def infer_objects(self): def fillna(self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None): - """ - Fill NA/NaN values using the specified method + """Fill NA/NaN values using the specified method Parameters ---------- @@ -5994,8 +5991,7 @@ def fillna(self, value=None, method=None, axis=None, inplace=False, 0 0.0 2.0 2.0 0 1 3.0 4.0 NaN 1 2 NaN 1.0 NaN 5 - 3 NaN 3.0 NaN 4 - """ + 3 NaN 3.0 NaN 4""" inplace = validate_bool_kwarg(inplace, 'inplace') value, method = validate_fillna_kwargs(value, method) @@ -8913,8 +8909,7 @@ def slice_shift(self, periods=1, axis=0): return new_obj.__finalize__(self) def tshift(self, periods=1, freq=None, axis=0): - """ - Shift the time index, using the index's frequency if available. + """Shift the time index, using the index's frequency if available. Parameters ---------- @@ -8933,8 +8928,7 @@ def tshift(self, periods=1, freq=None, axis=0): Returns ------- - shifted : NDFrame - """ + shifted : NDFrame""" index = self._get_axis(axis) if freq is None: diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index a17e2ce7f1ef5..ed407ea95a8d2 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1020,7 +1020,9 @@ def true_and_notna(x, *args, **kwargs): return filtered def nunique(self, dropna=True): - """ Returns number of unique elements in the group """ + """ + Returns number of unique elements in the group + """ ids, _, _ = self.grouper.group_info val = self.obj.get_values() @@ -1083,7 +1085,14 @@ def describe(self, **kwargs): def value_counts(self, normalize=False, sort=True, ascending=False, bins=None, dropna=True): - + """ + :param normalize: + :param sort: + :param ascending: + :param bins: + :param dropna: + :return: + """ from pandas.core.reshape.tile import cut from pandas.core.reshape.merge import _get_join_indexers @@ -1490,7 +1499,9 @@ def _fill(self, direction, limit=None): return concat((self._wrap_transformed_output(output), res), axis=1) def count(self): - """ Compute count of group, excluding missing values """ + """ + Compute count of group, excluding missing values + """ from pandas.core.dtypes.missing import _isna_ndarraylike as _isna data, _ = self._get_data_to_aggregate() diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 253860d83f49e..4f3747f5b244b 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -167,7 +167,7 @@ class providing the base-class of operations. dtype: int64 """) -_pipe_template = """\ +_pipe_template = """ Apply a function `func` with arguments to this %(klass)s object and return the function's result. @@ -716,6 +716,12 @@ def _iterate_slices(self): yield self._selection_name, self._selected_obj def transform(self, func, *args, **kwargs): + """ + :param func: + :param args: + :param kwargs: + :return: + """ raise AbstractMethodError(self) def _cumcount_array(self, ascending=True): @@ -1306,6 +1312,25 @@ def last(x): numeric_only=False) cls.last = groupby_function('last', 'last', last_compat, numeric_only=False) + cls.sum.__doc__ = """ + sum + """ + cls.prod.__doc__ = """ + prod + """ + cls.min.__doc__ = """ + min + """ + cls.max.__doc__ = """ + max + """ + cls.first.__doc__= """ + first + """ + cls.last.__doc__=""" + last + """ + @Substitution(name='groupby') @Appender(_doc_template) diff --git a/pandas/core/series.py b/pandas/core/series.py index 8d4d7677cca44..2f4d10f62b3f9 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1503,8 +1503,7 @@ def mode(self, dropna=True): return algorithms.mode(self, dropna=dropna) def unique(self): - """ - Return unique values of Series object. + """Return unique values of Series object. Uniques are returned in order of appearance. Hash table-based unique, therefore does NOT sort. @@ -1545,8 +1544,7 @@ def unique(self): >>> pd.Series(pd.Categorical(list('baabc'), categories=list('abc'), ... ordered=True)).unique() [b, a, c] - Categories (3, object): [a < b < c] - """ + Categories (3, object): [a < b < c]""" result = super(Series, self).unique() if is_datetime64tz_dtype(self.dtype): @@ -2903,8 +2901,7 @@ def argsort(self, axis=0, kind='quicksort', order=None): dtype='int64').__finalize__(self) def nlargest(self, n=5, keep='first'): - """ - Return the largest `n` elements. + """Return the largest `n` elements. Parameters ---------- @@ -2994,13 +2991,11 @@ def nlargest(self, n=5, keep='first'): Malta 434000 Maldives 434000 Brunei 434000 - dtype: int64 - """ + dtype: int64""" return algorithms.SelectNSeries(self, n=n, keep=keep).nlargest() def nsmallest(self, n=5, keep='first'): - """ - Return the smallest `n` elements. + """Return the smallest `n` elements. Parameters ---------- @@ -3089,8 +3084,7 @@ def nsmallest(self, n=5, keep='first'): Nauru 11300 Tuvalu 11300 Anguilla 11300 - dtype: int64 - """ + dtype: int64""" return algorithms.SelectNSeries(self, n=n, keep=keep).nsmallest() def swaplevel(self, i=-2, j=-1, copy=True): diff --git a/pandas/core/window.py b/pandas/core/window.py index 68a36fb2a6999..704d7382533c0 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -1225,7 +1225,9 @@ def var(self, ddof=1, *args, **kwargs): check_minp=_require_min_periods(1), ddof=ddof, **kwargs) - _shared_docs['skew'] = """Unbiased %(name)s skewness""" + _shared_docs['skew'] = """ + Unbiased %(name)s skewness + """ def skew(self, **kwargs): return self._apply('roll_skew', 'skew', diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index ec6743e205848..3f8660d9dad6e 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2301,8 +2301,7 @@ def plot_group(group, ax): def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None, xrot=None, ylabelsize=None, yrot=None, ax=None, sharex=False, sharey=False, figsize=None, layout=None, bins=10, **kwds): - """ - Make a histogram of the DataFrame's. + """Make a histogram of the DataFrame's. A `histogram`_ is a representation of the distribution of data. This function calls :meth:`matplotlib.pyplot.hist`, on each series in @@ -2376,8 +2375,7 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None, ... 'length': [1.5, 0.5, 1.2, 0.9, 3], ... 'width': [0.7, 0.2, 0.15, 0.2, 1.1] ... }, index= ['pig', 'rabbit', 'duck', 'chicken', 'horse']) - >>> hist = df.hist(bins=3) - """ + >>> hist = df.hist(bins=3)""" _raise_if_no_mpl() _converter._WARN = False if by is not None: