Skip to content

Commit f24e476

Browse files
committed
ENH: gb.is_monotonic_increasing pandas-dev#17015 minor fixes for @jreback
1 parent 2c3002f commit f24e476

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

doc/source/whatsnew/v0.21.1.txt

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Other Enhancements
2323

2424
- :meth:`Timestamp.timestamp` is now available in Python 2.7. (:issue:`17329`)
2525
- :class:`Grouper` and :class:`TimeGrouper` now have a friendly repr output (:issue:`18203`).
26-
- :meth: groupby.is_monotonic_increasing and :meth: .is_monotonic_decreasing extend :meth: Series.is_monotonic_increasing to groups, returning whether each group is monotonically increasing or decreasing, respectively. (:issue:`17015`)
2726
-
2827

2928
.. _whatsnew_0211.deprecations:

doc/source/whatsnew/v0.22.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Other Enhancements
4545
- Improved wording of ``ValueError`` raised in :func:`to_datetime` when ``unit=`` is passed with a non-convertible value (:issue:`14350`)
4646
- :func:`Series.fillna` now accepts a Series or a dict as a ``value`` for a categorical dtype (:issue:`17033`)
4747
- :func:`pandas.read_clipboard` updated to use qtpy, falling back to PyQt5 and then PyQt4, adding compatibility with Python3 and multiple python-qt bindings (:issue:`17722`)
48+
- :meth: groupby.is_monotonic_increasing and :meth: .is_monotonic_decreasing extend :meth: Series.is_monotonic_increasing to groups, returning whether each group is monotonically increasing or decreasing, respectively. (:issue:`17015`)
49+
-
4850

4951
.. _whatsnew_0220.api_breaking:
5052

pandas/core/groupby.py

+8
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,8 @@ def is_monotonic_increasing(self):
18341834
18351835
Equivalent to ``.apply(lambda x: x.is_monotonic_increasing)``.
18361836
1837+
.. versionadded:: 0.22.0
1838+
18371839
Examples
18381840
--------
18391841
>>> source_dict = {
@@ -1848,6 +1850,10 @@ def is_monotonic_increasing(self):
18481850
cat_b False
18491851
Name: C, dtype: bool
18501852
1853+
See Also
1854+
--------
1855+
pandas.Series.is_monotonic_increasing
1856+
pandas.Index.is_monotonic_increasing
18511857
"""
18521858
return self.apply(lambda x: x.is_monotonic_increasing)
18531859

@@ -1859,6 +1865,8 @@ def is_monotonic_decreasing(self):
18591865
18601866
Equivalent to ``.apply(lambda x: x.is_monotonic_decreasing)``.
18611867
1868+
.. versionadded:: 0.22.0
1869+
18621870
Examples
18631871
--------
18641872
>>> source_dict = {

pandas/tests/groupby/test_groupby.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@ def test_group_shift_with_null_key(self):
24752475
# Generate a moderately large dataframe with occasional missing
24762476
# values in column `B`, and then group by [`A`, `B`]. This should
24772477
# force `-1` in `labels` array of `g.grouper.group_info` exactly
2478-
# at those places, where the group-by key is partilly missing.
2478+
# at those places, where the group-by key is partially missing.
24792479
df = DataFrame([(i % 12, i % 3 if i % 3 else np.nan, i)
24802480
for i in range(n_rows)], dtype=float,
24812481
columns=["A", "B", "Z"], index=None)
@@ -2601,13 +2601,16 @@ def test_cummin_cummax(self):
26012601
tm.assert_series_equal(result, expected)
26022602

26032603
@pytest.mark.parametrize('in_vals, out_vals', [
2604+
26042605
# Basics: strictly increasing (T), strictly decreasing (F),
26052606
# abs val increasing (F), non-strictly increasing (T)
26062607
([1, 2, 5, 3, 2, 0, 4, 5, -6, 1, 1],
26072608
[True, False, False, True]),
2609+
26082610
# Test with inf vals
26092611
([1, 2.1, np.inf, 3, 2, np.inf, -np.inf, 5, 11, 1, -np.inf],
26102612
[True, False, True, False]),
2613+
26112614
# Test with nan vals; should always be False
26122615
([1, 2, np.nan, 3, 2, np.nan, np.nan, 5, -np.inf, 1, np.nan],
26132616
[False, False, False, False]),
@@ -2620,8 +2623,8 @@ def test_is_monotonic_increasing(self, in_vals, out_vals):
26202623
'C': in_vals}
26212624
df = pd.DataFrame(source_dict)
26222625
result = df.groupby('B').C.is_monotonic_increasing()
2623-
expected = pd.Series(index=list('abcd'), data=out_vals, name='C')
2624-
expected.index.name = 'B'
2626+
index = Index(list('abcd'), name='B')
2627+
expected = pd.Series(index=index, data=out_vals, name='C')
26252628
tm.assert_series_equal(result, expected)
26262629

26272630
# Also check result equal to manually taking x.is_monotonic_increasing.
@@ -2634,9 +2637,11 @@ def test_is_monotonic_increasing(self, in_vals, out_vals):
26342637
# abs val decreasing (F), non-strictly increasing (T)
26352638
([10, 9, 7, 3, 4, 5, -3, 2, 0, 1, 1],
26362639
[True, False, False, True]),
2640+
26372641
# Test with inf vals
26382642
([np.inf, 1, -np.inf, np.inf, 2, -3, -np.inf, 5, -3, -np.inf, -np.inf],
26392643
[True, True, False, True]),
2644+
26402645
# Test with nan vals; should always be False
26412646
([1, 2, np.nan, 3, 2, np.nan, np.nan, 5, -np.inf, 1, np.nan],
26422647
[False, False, False, False]),
@@ -2650,8 +2655,8 @@ def test_is_monotonic_decreasing(self, in_vals, out_vals):
26502655

26512656
df = pd.DataFrame(source_dict)
26522657
result = df.groupby('B').C.is_monotonic_decreasing()
2653-
expected = pd.Series(index=list('abcd'), data=out_vals, name='C')
2654-
expected.index.name = 'B'
2658+
index = Index(list('abcd'), name='B')
2659+
expected = pd.Series(index=index, data=out_vals, name='C')
26552660
tm.assert_series_equal(result, expected)
26562661

26572662
def test_apply_numeric_coercion_when_datetime(self):

pandas/tests/groupby/test_whitelist.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_regression_whitelist_methods(
184184
axis, skipna, sort):
185185
# GH6944
186186
# GH 17537
187-
# explicity test the whitelest methods
187+
# explicitly test the whitelist methods
188188

189189
if axis == 0:
190190
frame = raw_frame
@@ -250,7 +250,8 @@ def test_tab_completion(mframe):
250250
'take', 'tshift', 'pct_change', 'any', 'mad', 'corr', 'corrwith',
251251
'cov', 'dtypes', 'ndim', 'diff', 'idxmax', 'idxmin',
252252
'ffill', 'bfill', 'pad', 'backfill', 'rolling', 'expanding', 'pipe',
253-
'is_monotonic_increasing', 'is_monotonic_decreasing'}
253+
'is_monotonic_increasing', 'is_monotonic_decreasing'
254+
}
254255
assert results == expected
255256

256257

0 commit comments

Comments
 (0)