Skip to content

Commit be0f7b1

Browse files
authored
chore: deprecate LazyFrame.gather_every in main namespace (but maintain it in stable.v1) (#2103)
* chore: deprecate LazyFrame.gather_every in main namespace * fix typo * fix _version
1 parent 77a0150 commit be0f7b1

File tree

12 files changed

+73
-15
lines changed

12 files changed

+73
-15
lines changed

docs/backcompat.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ before making any change.
113113

114114
The following are differences between the main Narwhals namespace and `narwhals.stable.v1`:
115115

116+
- Since Narwhals 1.29.0, `LazyFrame.gather_every` has been deprecated from the main namespace.
117+
116118
- Since Narwhals 1.24.1, an empty or all-null object-dtype pandas Series is inferred to
117119
be of dtype `String`. Previously, it would have been inferred as `Object`.
118120

narwhals/dataframe.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from narwhals.utils import flatten
3535
from narwhals.utils import generate_repr
3636
from narwhals.utils import is_sequence_but_not_str
37+
from narwhals.utils import issue_deprecation_warning
3738
from narwhals.utils import parse_version
3839

3940
if TYPE_CHECKING:
@@ -3140,13 +3141,25 @@ def lazy(self: Self) -> Self:
31403141
def gather_every(self: Self, n: int, offset: int = 0) -> Self:
31413142
r"""Take every nth row in the DataFrame and return as a new DataFrame.
31423143
3144+
!!! warning
3145+
`LazyFrame.gather_every` is deprecated and will be removed in a future version.
3146+
Note: this will remain available in `narwhals.stable.v1`.
3147+
See [stable api](../backcompat.md/) for more information.
3148+
31433149
Arguments:
31443150
n: Gather every *n*-th row.
31453151
offset: Starting index.
31463152
31473153
Returns:
31483154
The LazyFrame containing only the selected rows.
31493155
"""
3156+
msg = (
3157+
"`LazyFrame.gather_every` is deprecated and will be removed in a future version.\n\n"
3158+
"Note: this will remain available in `narwhals.stable.v1`.\n"
3159+
"See https://narwhals-dev.github.io/narwhals/backcompat/ for more information.\n"
3160+
)
3161+
issue_deprecation_warning(msg, _version="1.29.0")
3162+
31503163
return super().gather_every(n=n, offset=offset)
31513164

31523165
def unpivot(

narwhals/expr.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ def sort(self: Self, *, descending: bool = False, nulls_last: bool = False) -> S
10961096
"Note: this will remain available in `narwhals.stable.v1`.\n"
10971097
"See https://narwhals-dev.github.io/narwhals/backcompat/ for more information.\n"
10981098
)
1099-
issue_deprecation_warning(msg, _version="1.22.0")
1099+
issue_deprecation_warning(msg, _version="1.23.0")
11001100
return self.__class__(
11011101
lambda plx: self._to_compliant_expr(plx).sort(
11021102
descending=descending, nulls_last=nulls_last
@@ -1485,7 +1485,7 @@ def sample(
14851485
"Note: this will remain available in `narwhals.stable.v1`.\n"
14861486
"See https://narwhals-dev.github.io/narwhals/backcompat/ for more information.\n"
14871487
)
1488-
issue_deprecation_warning(msg, _version="1.22.0")
1488+
issue_deprecation_warning(msg, _version="1.23.0")
14891489
return self.__class__(
14901490
lambda plx: self._to_compliant_expr(plx).sample(
14911491
n, fraction=fraction, with_replacement=with_replacement, seed=seed
@@ -1753,7 +1753,7 @@ def head(self: Self, n: int = 10) -> Self:
17531753
"Note: this will remain available in `narwhals.stable.v1`.\n"
17541754
"See https://narwhals-dev.github.io/narwhals/backcompat/ for more information.\n"
17551755
)
1756-
issue_deprecation_warning(msg, _version="1.22.0")
1756+
issue_deprecation_warning(msg, _version="1.23.0")
17571757
return self.__class__(
17581758
lambda plx: self._to_compliant_expr(plx).head(n),
17591759
self._metadata.with_kind_and_extra_open_window(ExprKind.FILTRATION),
@@ -1781,7 +1781,7 @@ def tail(self: Self, n: int = 10) -> Self:
17811781
"Note: this will remain available in `narwhals.stable.v1`.\n"
17821782
"See https://narwhals-dev.github.io/narwhals/backcompat/ for more information.\n"
17831783
)
1784-
issue_deprecation_warning(msg, _version="1.22.0")
1784+
issue_deprecation_warning(msg, _version="1.23.0")
17851785
return self.__class__(
17861786
lambda plx: self._to_compliant_expr(plx).tail(n),
17871787
self._metadata.with_kind_and_extra_open_window(ExprKind.FILTRATION),
@@ -1876,7 +1876,7 @@ def gather_every(self: Self, n: int, offset: int = 0) -> Self:
18761876
"Note: this will remain available in `narwhals.stable.v1`.\n"
18771877
"See https://narwhals-dev.github.io/narwhals/backcompat/ for more information.\n"
18781878
)
1879-
issue_deprecation_warning(msg, _version="1.22.0")
1879+
issue_deprecation_warning(msg, _version="1.23.0")
18801880
return self.__class__(
18811881
lambda plx: self._to_compliant_expr(plx).gather_every(n=n, offset=offset),
18821882
self._metadata.with_kind_and_extra_open_window(ExprKind.FILTRATION),

narwhals/stable/v1/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,20 @@ def tail(self, n: int = 5) -> Self: # pragma: no cover
348348
"""
349349
return super().tail(n)
350350

351+
def gather_every(self: Self, n: int, offset: int = 0) -> Self:
352+
r"""Take every nth row in the DataFrame and return as a new DataFrame.
353+
354+
Arguments:
355+
n: Gather every *n*-th row.
356+
offset: Starting index.
357+
358+
Returns:
359+
The LazyFrame containing only the selected rows.
360+
"""
361+
return self._from_compliant_dataframe(
362+
self._compliant_frame.gather_every(n=n, offset=offset)
363+
)
364+
351365

352366
class Series(NwSeries[IntoSeriesT]):
353367
"""Narwhals Series, backed by a native series.

tests/expr_and_series/arg_true_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def test_arg_true(constructor_eager: ConstructorEager) -> None:
1414
expected = {"a": [1, 2]}
1515
assert_equal_data(result, expected)
1616

17-
with pytest.deprecated_call():
17+
with pytest.deprecated_call(
18+
match="is deprecated and will be removed in a future version"
19+
):
1820
df.select(nw.col("a").is_null().arg_true())
1921

2022

tests/expr_and_series/gather_every_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def test_gather_every_expr(
2222

2323
assert_equal_data(result, expected)
2424

25-
with pytest.deprecated_call():
25+
with pytest.deprecated_call(
26+
match="is deprecated and will be removed in a future version"
27+
):
2628
df.select(nw_main.col("a").gather_every(n=n, offset=offset))
2729

2830

tests/expr_and_series/head_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def test_head(
1919
expected = {"a": [1, 2]}
2020
assert_equal_data(result, expected)
2121

22-
with pytest.deprecated_call():
22+
with pytest.deprecated_call(
23+
match="is deprecated and will be removed in a future version"
24+
):
2325
df.select(nw_main.col("a").head(5))
2426

2527

tests/expr_and_series/sample_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def test_expr_sample(constructor_eager: ConstructorEager) -> None:
2121
expected_series = (2,)
2222
assert result_series == expected_series
2323

24-
with pytest.deprecated_call():
24+
with pytest.deprecated_call(
25+
match="is deprecated and will be removed in a future version"
26+
):
2527
df.select(nw_main.col("a").sample(n=2))
2628

2729

tests/expr_and_series/sort_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def test_sort_expr(
3030
nw.col("b").sort(descending=descending, nulls_last=nulls_last),
3131
)
3232
assert_equal_data(result, expected)
33-
with pytest.deprecated_call():
33+
with pytest.deprecated_call(
34+
match="is deprecated and will be removed in a future version"
35+
):
3436
df.select(
3537
"a",
3638
nw_main.col("b").sort(descending=descending, nulls_last=nulls_last),

tests/expr_and_series/tail_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def test_tail(
1919
expected = {"a": [2, 3]}
2020
assert_equal_data(result, expected)
2121

22-
with pytest.deprecated_call():
22+
with pytest.deprecated_call(
23+
match="is deprecated and will be removed in a future version"
24+
):
2325
df.select(nw_main.col("a").tail(5))
2426

2527

0 commit comments

Comments
 (0)