Skip to content

Commit 0e83e20

Browse files
Deprecate first and last (#14583)
This PR deprecates first and last APIs to bring parity with pandas, where these APIs were deprecated starting 2.1.0
1 parent 9b478b0 commit 0e83e20

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

python/cudf/cudf/core/indexed_frame.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,12 @@ def first(self, offset):
33183318
2018-04-09 1
33193319
2018-04-11 2
33203320
"""
3321+
# Do not remove until pandas 3.0 support is added.
3322+
warnings.warn(
3323+
"first is deprecated and will be removed in a future version. "
3324+
"Please create a mask and filter using `.loc` instead",
3325+
FutureWarning,
3326+
)
33213327
return self._first_or_last(
33223328
offset,
33233329
idx=0,
@@ -3364,6 +3370,12 @@ def last(self, offset):
33643370
2018-04-13 3
33653371
2018-04-15 4
33663372
"""
3373+
# Do not remove until pandas 3.0 support is added.
3374+
warnings.warn(
3375+
"last is deprecated and will be removed in a future version. "
3376+
"Please create a mask and filter using `.loc` instead",
3377+
FutureWarning,
3378+
)
33673379
return self._first_or_last(
33683380
offset,
33693381
idx=-1,

python/cudf/cudf/tests/test_datetime.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
import warnings
1414
import cudf.testing.dataset_generator as dataset_generator
1515
from cudf import DataFrame, Series
16-
from cudf.core._compat import PANDAS_GE_150, PANDAS_LT_140, PANDAS_EQ_200
16+
from cudf.core._compat import (
17+
PANDAS_GE_150,
18+
PANDAS_LT_140,
19+
PANDAS_EQ_200,
20+
PANDAS_GE_210,
21+
)
1722
from cudf.core.index import DatetimeIndex
1823
from cudf.testing._utils import (
1924
DATETIME_TYPES,
@@ -2070,8 +2075,10 @@ def test_first(idx, offset):
20702075
p = pd.Series(range(len(idx)), dtype="int64", index=idx)
20712076
g = cudf.from_pandas(p)
20722077

2073-
expect = p.first(offset=offset)
2074-
got = g.first(offset=offset)
2078+
with expect_warning_if(PANDAS_GE_210):
2079+
expect = p.first(offset=offset)
2080+
with pytest.warns(FutureWarning):
2081+
got = g.first(offset=offset)
20752082

20762083
assert_eq(expect, got)
20772084

@@ -2100,8 +2107,10 @@ def test_first_start_at_end_of_month(idx, offset):
21002107
p = pd.Series(range(len(idx)), index=idx)
21012108
g = cudf.from_pandas(p)
21022109

2103-
expect = p.first(offset=offset)
2104-
got = g.first(offset=offset)
2110+
with expect_warning_if(PANDAS_GE_210):
2111+
expect = p.first(offset=offset)
2112+
with pytest.warns(FutureWarning):
2113+
got = g.first(offset=offset)
21052114

21062115
assert_eq(expect, got)
21072116

@@ -2137,8 +2146,10 @@ def test_last(idx, offset):
21372146
p = pd.Series(range(len(idx)), dtype="int64", index=idx)
21382147
g = cudf.from_pandas(p)
21392148

2140-
expect = p.last(offset=offset)
2141-
got = g.last(offset=offset)
2149+
with expect_warning_if(PANDAS_GE_210):
2150+
expect = p.last(offset=offset)
2151+
with pytest.warns(FutureWarning):
2152+
got = g.last(offset=offset)
21422153

21432154
assert_eq(expect, got)
21442155

0 commit comments

Comments
 (0)