Skip to content

Commit cd20150

Browse files
committed
updated testcases & whatsnew
1 parent bef38c9 commit cd20150

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Deprecations
9999
- Deprecated ``axis=1`` in :meth:`DataFrame.groupby` and in :class:`Grouper` constructor, do ``frame.T.groupby(...)`` instead (:issue:`51203`)
100100
- Deprecated passing a :class:`DataFrame` to :meth:`DataFrame.from_records`, use :meth:`DataFrame.set_index` or :meth:`DataFrame.drop` instead (:issue:`51353`)
101101
- Deprecated accepting slices in :meth:`DataFrame.take`, call ``obj[slicer]`` or pass a sequence of integers instead (:issue:`51539`)
102+
- Deprecated ``axis=1`` in :meth:`DataFrame.resample`, do ``frame.T.resample(...)`` instead (:issue:`51778`)
102103
-
103104

104105
.. ---------------------------------------------------------------------------

pandas/tests/resample/test_datetime_index.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -641,12 +641,16 @@ def test_resample_dup_index():
641641
columns=[Period(year=2000, month=i + 1, freq="M") for i in range(12)],
642642
)
643643
df.iloc[3, :] = np.nan
644-
result = df.resample("Q", axis=1).mean()
645-
msg = "DataFrame.groupby with axis=1 is deprecated"
646-
with tm.assert_produces_warning(FutureWarning, match=msg):
647-
expected = df.groupby(lambda x: int((x.month - 1) / 3), axis=1).mean()
648-
expected.columns = [Period(year=2000, quarter=i + 1, freq="Q") for i in range(4)]
649-
tm.assert_frame_equal(result, expected)
644+
warning_msg = "DataFrame.resample with axis=1 is deprecated."
645+
with tm.assert_produces_warning(FutureWarning, match=warning_msg):
646+
result = df.resample("Q", axis=1).mean()
647+
msg = "DataFrame.groupby with axis=1 is deprecated"
648+
with tm.assert_produces_warning(FutureWarning, match=msg):
649+
expected = df.groupby(lambda x: int((x.month - 1) / 3), axis=1).mean()
650+
expected.columns = [
651+
Period(year=2000, quarter=i + 1, freq="Q") for i in range(4)
652+
]
653+
tm.assert_frame_equal(result, expected)
650654

651655

652656
def test_resample_reresample(unit):
@@ -729,9 +733,11 @@ def test_resample_axis1(unit):
729733
rng = date_range("1/1/2000", "2/29/2000").as_unit(unit)
730734
df = DataFrame(np.random.randn(3, len(rng)), columns=rng, index=["a", "b", "c"])
731735

732-
result = df.resample("M", axis=1).mean()
733-
expected = df.T.resample("M").mean().T
734-
tm.assert_frame_equal(result, expected)
736+
warning_msg = "DataFrame.resample with axis=1 is deprecated."
737+
with tm.assert_produces_warning(FutureWarning, match=warning_msg):
738+
result = df.resample("M", axis=1).mean()
739+
expected = df.T.resample("M").mean().T
740+
tm.assert_frame_equal(result, expected)
735741

736742

737743
@pytest.mark.parametrize("freq", ["t", "5t", "15t", "30t", "4h", "12h"])

pandas/tests/resample/test_resample_api.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,13 @@ def test_multi_agg_axis_1_raises(func):
570570
index = date_range(datetime(2005, 1, 1), datetime(2005, 1, 10), freq="D")
571571
index.name = "date"
572572
df = DataFrame(np.random.rand(10, 2), columns=list("AB"), index=index).T
573-
res = df.resample("M", axis=1)
574-
with pytest.raises(NotImplementedError, match="axis other than 0 is not supported"):
575-
res.agg(func)
573+
warning_msg = "DataFrame.resample with axis=1 is deprecated."
574+
with tm.assert_produces_warning(FutureWarning, match=warning_msg):
575+
res = df.resample("M", axis=1)
576+
with pytest.raises(
577+
NotImplementedError, match="axis other than 0 is not supported"
578+
):
579+
res.agg(func)
576580

577581

578582
def test_agg_nested_dicts():

0 commit comments

Comments
 (0)