Skip to content

Commit f5589bf

Browse files
committed
ENH: gb.is_monotonic_increasing pandas-dev#17015 fix rebase conflicts
1 parent c5a70dd commit f5589bf

File tree

4 files changed

+72
-12
lines changed

4 files changed

+72
-12
lines changed

doc/source/whatsnew/v0.21.0.txt

+10
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,21 @@ New keywords
309309
- :func:`read_feather` has gained the ``nthreads`` parameter for multi-threaded operations (:issue:`16359`)
310310
- :func:`DataFrame.clip()` and :func:`Series.clip()` have gained an ``inplace`` argument. (:issue:`15388`)
311311
- :func:`crosstab` has gained a ``margins_name`` parameter to define the name of the row / column that will contain the totals when ``margins=True``. (:issue:`15972`)
312+
<<<<<<< HEAD
312313
- :func:`read_json` now accepts a ``chunksize`` parameter that can be used when ``lines=True``. If ``chunksize`` is passed, read_json now returns an iterator which reads in ``chunksize`` lines with each iteration. (:issue:`17048`)
313314
- :func:`read_json` and :func:`~DataFrame.to_json` now accept a ``compression`` argument which allows them to transparently handle compressed files. (:issue:`17798`)
314315

315316
Various enhancements
316317
""""""""""""""""""""
318+
=======
319+
- :func:`DataFrame.select_dtypes` now accepts scalar values for include/exclude as well as list-like. (:issue:`16855`)
320+
- :func:`date_range` now accepts 'YS' in addition to 'AS' as an alias for start of year (:issue:`9313`)
321+
- :func:`date_range` now accepts 'Y' in addition to 'A' as an alias for end of year (:issue:`9313`)
322+
- Integration with `Apache Parquet <https://parquet.apache.org/>`__, including a new top-level :func:`read_parquet` and :func:`DataFrame.to_parquet` method, see :ref:`here <io.parquet>`.
323+
- :func:`DataFrame.add_prefix` and :func:`DataFrame.add_suffix` now accept strings containing the '%' character. (:issue:`17151`)
324+
- `read_*` methods can now infer compression from non-string paths, such as ``pathlib.Path`` objects (:issue:`17206`).
325+
- :func:`pd.read_sas()` now recognizes much more of the most frequently used date (datetime) formats in SAS7BDAT files (:issue:`15871`).
326+
- :func:`DataFrame.items` and :func:`Series.items` is now present in both Python 2 and 3 and is lazy in all cases (:issue:`13918`, :issue:`17213`)
317327

318328
- Improved the import time of pandas by about 2.25x. (:issue:`16764`)
319329
- Support for `PEP 519 -- Adding a file system path protocol

doc/source/whatsnew/v0.21.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Other Enhancements
2222
^^^^^^^^^^^^^^^^^^
2323

2424
- :meth:`Timestamp.timestamp` is now available in Python 2.7. (:issue:`17329`)
25-
-
25+
- :func: groupby.is_monotonic_increasing and .is_monotonic_decreasing extend Series.is_monotonic_increasing to groups, returning whether each group is monotonically increasing or decreasing, respectively. (:issue:`17015`)
2626
-
2727

2828
.. _whatsnew_0211.deprecations:

pandas/core/groupby.py

+49
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,55 @@ def pipe(self, func, *args, **kwargs):
17431743
"""
17441744
return _pipe(self, func, *args, **kwargs)
17451745

1746+
@Substitution(name='groupby')
1747+
@Appender(_doc_template)
1748+
def is_monotonic_increasing(self):
1749+
"""
1750+
Returns whether each group is monotonically increasing.
1751+
1752+
Equivalent to ``.apply(lambda x: x.is_monotonic_increasing)``.
1753+
1754+
Examples
1755+
--------
1756+
>>> source_dict = {
1757+
... 'A': ['this', 'col', 'is', 'entirely', 'irrelevant', '.'],
1758+
... 'B': ['cat_a', 'cat_a', 'cat_a', 'cat_b', 'cat_b', 'cat_b'],
1759+
... 'C': [1, 2, 3, 2, 2, 0]}
1760+
1761+
>>> df = pd.DataFrame(source_dict)
1762+
... df.groupby(['B']).C.is_monotonic_increasing()
1763+
B
1764+
cat_a True
1765+
cat_b False
1766+
Name: C, dtype: bool
1767+
1768+
"""
1769+
return self.apply(lambda x: x.is_monotonic_increasing)
1770+
1771+
@Substitution(name='groupby')
1772+
@Appender(_doc_template)
1773+
def is_monotonic_decreasing(self):
1774+
"""
1775+
Returns whether each group is monotonically decreasing.
1776+
1777+
Equivalent to ``.apply(lambda x: x.is_monotonic_decreasing)``.
1778+
1779+
Examples
1780+
--------
1781+
>>> source_dict = {
1782+
... 'A': ['this', 'col', 'is', 'entirely', 'irrelevant', '.'],
1783+
... 'B': ['cat_a', 'cat_a', 'cat_a', 'cat_b', 'cat_b', 'cat_b'],
1784+
... 'C': [1, 2, 3, 2, 2, 0]}
1785+
1786+
>>> df = pd.DataFrame(source_dict)
1787+
... df.groupby(['B']).C.is_monotonic_decreasing()
1788+
B
1789+
cat_a False
1790+
cat_b True
1791+
Name: C, dtype: bool
1792+
"""
1793+
return self.apply(lambda x: x.is_monotonic_decreasing)
1794+
17461795

17471796
GroupBy._add_numeric_operations()
17481797

pandas/tests/groupby/test_whitelist.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,18 @@ def test_groupby_blacklist(df_letters):
239239
def test_tab_completion(mframe):
240240
grp = mframe.groupby(level='second')
241241
results = set([v for v in dir(grp) if not v.startswith('_')])
242-
expected = {
243-
'A', 'B', 'C', 'agg', 'aggregate', 'apply', 'boxplot', 'filter',
244-
'first', 'get_group', 'groups', 'hist', 'indices', 'last', 'max',
245-
'mean', 'median', 'min', 'ngroups', 'nth', 'ohlc', 'plot',
246-
'prod', 'size', 'std', 'sum', 'transform', 'var', 'sem', 'count',
247-
'nunique', 'head', 'describe', 'cummax', 'quantile',
248-
'rank', 'cumprod', 'tail', 'resample', 'cummin', 'fillna',
249-
'cumsum', 'cumcount', 'ngroup', 'all', 'shift', 'skew',
250-
'take', 'tshift', 'pct_change', 'any', 'mad', 'corr', 'corrwith',
251-
'cov', 'dtypes', 'ndim', 'diff', 'idxmax', 'idxmin',
252-
'ffill', 'bfill', 'pad', 'backfill', 'rolling', 'expanding', 'pipe'}
242+
expected = set(
243+
['A', 'B', 'C', 'agg', 'aggregate', 'apply', 'boxplot', 'filter',
244+
'first', 'get_group', 'groups', 'hist', 'indices', 'last', 'max',
245+
'mean', 'median', 'min', 'ngroups', 'nth', 'ohlc', 'plot',
246+
'prod', 'size', 'std', 'sum', 'transform', 'var', 'sem', 'count',
247+
'nunique', 'head', 'describe', 'cummax', 'quantile',
248+
'rank', 'cumprod', 'tail', 'resample', 'cummin', 'fillna',
249+
'cumsum', 'cumcount', 'ngroup', 'all', 'shift', 'skew',
250+
'take', 'tshift', 'pct_change', 'any', 'mad', 'corr', 'corrwith',
251+
'cov', 'dtypes', 'ndim', 'diff', 'idxmax', 'idxmin',
252+
'ffill', 'bfill', 'pad', 'backfill', 'rolling', 'expanding', 'pipe',
253+
'is_monotonic_increasing', 'is_monotonic_decreasing'])
253254
assert results == expected
254255

255256

0 commit comments

Comments
 (0)