Skip to content

Commit 1aff629

Browse files
committed
Add tests and whatsnew
1 parent 0ccda51 commit 1aff629

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

doc/source/whatsnew/v1.2.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ Other enhancements
235235
- Improve error reporting for :meth:`DataFrame.merge()` when invalid merge column definitions were given (:issue:`16228`)
236236
- Improve numerical stability for :meth:`Rolling.skew()`, :meth:`Rolling.kurt()`, :meth:`Expanding.skew()` and :meth:`Expanding.kurt()` through implementation of Kahan summation (:issue:`6929`)
237237
- Improved error reporting for subsetting columns of a :class:`DataFrameGroupBy` with ``axis=1`` (:issue:`37725`)
238+
- Add support for ``min_count`` keyword for :meth:`DataFrame.groupby` and :meth:`DataFrame.resample` for functions ``min``, ``max``, ``first`` and ``last`` (:issue:`37821`, :issue:`37768`)
238239

239240
.. ---------------------------------------------------------------------------
240241

pandas/tests/groupby/aggregate/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ def weird_func(x):
643643
@pytest.mark.parametrize("func", ["first", "last", "max", "min"])
644644
def test_min_count_implementation_min_max_first_last(func):
645645
# GH#37821
646-
df = DataFrame({"a": [1] * 3, "b": [np.nan] * 3})
646+
df = DataFrame({"a": [1] * 3, "b": [1, np.nan, np.nan]})
647647
result = getattr(df.groupby("a"), func)(min_count=2)
648648
expected = DataFrame({"b": [np.nan]}, index=Index([1], name="a"))
649649
tm.assert_frame_equal(result, expected)

pandas/tests/resample/test_datetime_index.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,3 +1785,16 @@ def test_resample_calendar_day_with_dst(
17851785
1.0, pd.date_range(first, exp_last, freq=freq_out, tz="Europe/Amsterdam")
17861786
)
17871787
tm.assert_series_equal(result, expected)
1788+
1789+
1790+
@pytest.mark.parametrize("func", ["min", "max", "first", "last"])
1791+
def test_resample_aggregate_functions_min_count(func):
1792+
# GH#37768
1793+
index = date_range(start="2020", freq="M", periods=3)
1794+
ser = Series([1, np.nan, np.nan], index)
1795+
result = getattr(ser.resample("Q"), func)(min_count=2)
1796+
expected = Series(
1797+
[np.nan],
1798+
index=DatetimeIndex(["2020-03-31"], dtype="datetime64[ns]", freq="Q-DEC"),
1799+
)
1800+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)