diff --git a/py-polars/docs/source/reference/dataframe/descriptive.rst b/py-polars/docs/source/reference/dataframe/descriptive.rst index 42e7b0ed7789..5c8b64086aeb 100644 --- a/py-polars/docs/source/reference/dataframe/descriptive.rst +++ b/py-polars/docs/source/reference/dataframe/descriptive.rst @@ -7,7 +7,6 @@ Descriptive :toctree: api/ DataFrame.approx_n_unique - DataFrame.approx_unique DataFrame.describe DataFrame.glimpse DataFrame.estimated_size diff --git a/py-polars/docs/source/reference/expressions/functions.rst b/py-polars/docs/source/reference/expressions/functions.rst index 9e457a12a280..6a4090246993 100644 --- a/py-polars/docs/source/reference/expressions/functions.rst +++ b/py-polars/docs/source/reference/expressions/functions.rst @@ -23,7 +23,6 @@ These functions are available from the polars module root and can be used as exp arctan2d arg_sort_by arg_where - avg coalesce concat_list concat_str diff --git a/py-polars/docs/source/reference/expressions/list.rst b/py-polars/docs/source/reference/expressions/list.rst index a674a96df7cd..1d794108bb18 100644 --- a/py-polars/docs/source/reference/expressions/list.rst +++ b/py-polars/docs/source/reference/expressions/list.rst @@ -19,14 +19,12 @@ The following methods are available under the `expr.list` attribute. Expr.list.count_match Expr.list.count_matches Expr.list.diff - Expr.list.difference Expr.list.eval Expr.list.explode Expr.list.first Expr.list.gather Expr.list.get Expr.list.head - Expr.list.intersection Expr.list.join Expr.list.last Expr.list.len @@ -44,10 +42,8 @@ The following methods are available under the `expr.list` attribute. Expr.list.slice Expr.list.sort Expr.list.sum - Expr.list.symmetric_difference Expr.list.tail Expr.list.take Expr.list.to_array Expr.list.to_struct - Expr.list.union Expr.list.unique diff --git a/py-polars/docs/source/reference/expressions/miscellaneous.rst b/py-polars/docs/source/reference/expressions/miscellaneous.rst index 9d4e277858d5..a1997ccb9031 100644 --- a/py-polars/docs/source/reference/expressions/miscellaneous.rst +++ b/py-polars/docs/source/reference/expressions/miscellaneous.rst @@ -6,6 +6,5 @@ Miscellaneous .. autosummary:: :toctree: api/ - Expr.cache Expr.from_json Expr.set_sorted diff --git a/py-polars/docs/source/reference/lazyframe/miscellaneous.rst b/py-polars/docs/source/reference/lazyframe/miscellaneous.rst index 7dba1aa7d61d..a8b4a44c81ac 100644 --- a/py-polars/docs/source/reference/lazyframe/miscellaneous.rst +++ b/py-polars/docs/source/reference/lazyframe/miscellaneous.rst @@ -23,7 +23,4 @@ Read/write logical plan :toctree: api/ LazyFrame.deserialize - LazyFrame.from_json - LazyFrame.read_json LazyFrame.serialize - LazyFrame.write_json diff --git a/py-polars/docs/source/reference/lazyframe/modify_select.rst b/py-polars/docs/source/reference/lazyframe/modify_select.rst index f6965462890f..f6dbe5b245c0 100644 --- a/py-polars/docs/source/reference/lazyframe/modify_select.rst +++ b/py-polars/docs/source/reference/lazyframe/modify_select.rst @@ -7,7 +7,6 @@ Manipulation/selection :toctree: api/ LazyFrame.approx_n_unique - LazyFrame.approx_unique LazyFrame.bottom_k LazyFrame.cast LazyFrame.clear diff --git a/py-polars/docs/source/reference/series/list.rst b/py-polars/docs/source/reference/series/list.rst index 2a7df12b290a..cdce24994f76 100644 --- a/py-polars/docs/source/reference/series/list.rst +++ b/py-polars/docs/source/reference/series/list.rst @@ -19,7 +19,6 @@ The following methods are available under the `Series.list` attribute. Series.list.count_match Series.list.count_matches Series.list.diff - Series.list.difference Series.list.eval Series.list.explode Series.list.first @@ -27,7 +26,6 @@ The following methods are available under the `Series.list` attribute. Series.list.get Series.list.head Series.list.join - Series.list.intersection Series.list.last Series.list.len Series.list.lengths @@ -44,10 +42,8 @@ The following methods are available under the `Series.list` attribute. Series.list.slice Series.list.sort Series.list.sum - Series.list.symmetric_difference Series.list.tail Series.list.take Series.list.to_array Series.list.to_struct - Series.list.union Series.list.unique diff --git a/py-polars/polars/__init__.py b/py-polars/polars/__init__.py index a53156430369..2700b7d3f5f2 100644 --- a/py-polars/polars/__init__.py +++ b/py-polars/polars/__init__.py @@ -91,7 +91,6 @@ arctan2d, arg_sort_by, arg_where, - avg, coalesce, col, collect_all, @@ -336,7 +335,6 @@ "arctan2", "arctan2d", "arg_sort_by", - "avg", "coalesce", "col", "collect_all", diff --git a/py-polars/polars/dataframe/frame.py b/py-polars/polars/dataframe/frame.py index e1d9f75c6e32..a2a7a0914079 100644 --- a/py-polars/polars/dataframe/frame.py +++ b/py-polars/polars/dataframe/frame.py @@ -3434,7 +3434,6 @@ def write_parquet( data_page_size, ) - @deprecate_renamed_parameter("connection_uri", "connection", version="0.18.9") @deprecate_renamed_parameter("if_exists", "if_table_exists", version="0.20.0") def write_database( self, @@ -6320,7 +6319,6 @@ def hstack( else: return self._from_pydf(self._df.hstack([s._s for s in columns])) - @deprecate_renamed_parameter("df", "other", version="0.18.8") def vstack(self, other: DataFrame, *, in_place: bool = False) -> Self: """ Grow this DataFrame vertically by stacking a DataFrame to it. @@ -9006,17 +9004,6 @@ def approx_n_unique(self) -> DataFrame: """ return self.lazy().approx_n_unique().collect(_eager=True) - @deprecate_renamed_function("approx_n_unique", version="0.18.12") - def approx_unique(self) -> DataFrame: - """ - Approximate count of unique values. - - .. deprecated:: 0.18.12 - This method has been renamed to :func:`DataFrame.approx_n_unique`. - - """ - return self.approx_n_unique() - def rechunk(self) -> Self: """ Rechunk the data in this DataFrame to a contiguous allocation. diff --git a/py-polars/polars/expr/expr.py b/py-polars/polars/expr/expr.py index a189e5f997da..3e57812e4da5 100644 --- a/py-polars/polars/expr/expr.py +++ b/py-polars/polars/expr/expr.py @@ -54,7 +54,6 @@ deprecate_renamed_function, deprecate_renamed_parameter, deprecate_saturating, - warn_closed_future_change, ) from polars.utils.meta import threadpool_size from polars.utils.various import _warn_null_comparison, no_default, sphinx_accessor @@ -3627,13 +3626,13 @@ def quantile( quantile = parse_as_expression(quantile) return self._from_pyexpr(self._pyexpr.quantile(quantile, interpolation)) - @deprecate_nonkeyword_arguments(["self", "breaks"], version="0.18.14") def cut( self, breaks: Sequence[float], + *, labels: Sequence[str] | None = None, - left_closed: bool = False, # noqa: FBT001 - include_breaks: bool = False, # noqa: FBT001 + left_closed: bool = False, + include_breaks: bool = False, ) -> Self: """ Bin continuous values into discrete categories. @@ -3706,16 +3705,14 @@ def cut( self._pyexpr.cut(breaks, labels, left_closed, include_breaks) ) - @deprecate_nonkeyword_arguments(["self", "quantiles"], version="0.18.14") - @deprecate_renamed_parameter("probs", "quantiles", version="0.18.8") - @deprecate_renamed_parameter("q", "quantiles", version="0.18.12") def qcut( self, quantiles: Sequence[float] | int, + *, labels: Sequence[str] | None = None, - left_closed: bool = False, # noqa: FBT001 - allow_duplicates: bool = False, # noqa: FBT001 - include_breaks: bool = False, # noqa: FBT001 + left_closed: bool = False, + allow_duplicates: bool = False, + include_breaks: bool = False, ) -> Self: """ Bin continuous values into discrete categories based on their quantiles. @@ -5557,7 +5554,6 @@ def interpolate(self, method: InterpolationMethod = "linear") -> Self: """ return self._from_pyexpr(self._pyexpr.interpolate(method)) - @warn_closed_future_change() def rolling_min( self, window_size: int | timedelta | str, @@ -5566,7 +5562,7 @@ def rolling_min( *, center: bool = False, by: str | None = None, - closed: ClosedInterval = "left", + closed: ClosedInterval = "right", warn_if_unsorted: bool = True, ) -> Self: """ @@ -5768,7 +5764,6 @@ def rolling_min( ) ) - @warn_closed_future_change() def rolling_max( self, window_size: int | timedelta | str, @@ -5777,7 +5772,7 @@ def rolling_max( *, center: bool = False, by: str | None = None, - closed: ClosedInterval = "left", + closed: ClosedInterval = "right", warn_if_unsorted: bool = True, ) -> Self: """ @@ -6002,7 +5997,6 @@ def rolling_max( ) ) - @warn_closed_future_change() def rolling_mean( self, window_size: int | timedelta | str, @@ -6011,7 +6005,7 @@ def rolling_mean( *, center: bool = False, by: str | None = None, - closed: ClosedInterval = "left", + closed: ClosedInterval = "right", warn_if_unsorted: bool = True, ) -> Self: """ @@ -6246,7 +6240,6 @@ def rolling_mean( ) ) - @warn_closed_future_change() def rolling_sum( self, window_size: int | timedelta | str, @@ -6255,7 +6248,7 @@ def rolling_sum( *, center: bool = False, by: str | None = None, - closed: ClosedInterval = "left", + closed: ClosedInterval = "right", warn_if_unsorted: bool = True, ) -> Self: """ @@ -6480,7 +6473,6 @@ def rolling_sum( ) ) - @warn_closed_future_change() def rolling_std( self, window_size: int | timedelta | str, @@ -6489,7 +6481,7 @@ def rolling_std( *, center: bool = False, by: str | None = None, - closed: ClosedInterval = "left", + closed: ClosedInterval = "right", ddof: int = 1, warn_if_unsorted: bool = True, ) -> Self: @@ -6724,7 +6716,6 @@ def rolling_std( ) ) - @warn_closed_future_change() def rolling_var( self, window_size: int | timedelta | str, @@ -6733,7 +6724,7 @@ def rolling_var( *, center: bool = False, by: str | None = None, - closed: ClosedInterval = "left", + closed: ClosedInterval = "right", ddof: int = 1, warn_if_unsorted: bool = True, ) -> Self: @@ -6968,7 +6959,6 @@ def rolling_var( ) ) - @warn_closed_future_change() def rolling_median( self, window_size: int | timedelta | str, @@ -6977,7 +6967,7 @@ def rolling_median( *, center: bool = False, by: str | None = None, - closed: ClosedInterval = "left", + closed: ClosedInterval = "right", warn_if_unsorted: bool = True, ) -> Self: """ @@ -7128,7 +7118,6 @@ def rolling_median( ) ) - @warn_closed_future_change() def rolling_quantile( self, quantile: float, @@ -7139,7 +7128,7 @@ def rolling_quantile( *, center: bool = False, by: str | None = None, - closed: ClosedInterval = "left", + closed: ClosedInterval = "right", warn_if_unsorted: bool = True, ) -> Self: """ @@ -9003,24 +8992,6 @@ def shrink_dtype(self) -> Self: """ return self._from_pyexpr(self._pyexpr.shrink_dtype()) - @deprecate_function( - "This method now does nothing. It has been superseded by the" - " `comm_subexpr_elim` setting on `LazyFrame.collect`, which automatically" - " caches expressions that are equal.", - version="0.18.9", - ) - def cache(self) -> Self: - """ - Cache this expression so that it only is executed once per context. - - .. deprecated:: 0.18.9 - This method now does nothing. It has been superseded by the - `comm_subexpr_elim` setting on `LazyFrame.collect`, which automatically - caches expressions that are equal. - - """ - return self - def replace( self, mapping: dict[Any, Any], diff --git a/py-polars/polars/expr/list.py b/py-polars/polars/expr/list.py index e3f9a994c7a0..710c7a6c4206 100644 --- a/py-polars/polars/expr/list.py +++ b/py-polars/polars/expr/list.py @@ -1238,50 +1238,6 @@ def set_symmetric_difference(self, other: IntoExpr) -> Expr: other = parse_as_expression(other, str_as_lit=False) return wrap_expr(self._pyexpr.list_set_operation(other, "symmetric_difference")) - @deprecate_renamed_function("set_union", version="0.18.10") - def union(self, other: IntoExpr) -> Expr: - """ - Compute the SET UNION between the elements in this list and the elements of `other`. - - .. deprecated:: 0.18.10 - This method has been renamed to :meth:`set_union`. - - """ # noqa: W505 - return self.set_union(other) - - @deprecate_renamed_function("set_difference", version="0.18.10") - def difference(self, other: IntoExpr) -> Expr: - """ - Compute the SET DIFFERENCE between the elements in this list and the elements of `other`. - - .. deprecated:: 0.18.10 - This method has been renamed to :meth:`set_difference`. - - """ # noqa: W505 - return self.set_difference(other) - - @deprecate_renamed_function("set_intersection", version="0.18.10") - def intersection(self, other: IntoExpr) -> Expr: - """ - Compute the SET INTERSECTION between the elements in this list and the elements of `other`. - - .. deprecated:: 0.18.10 - This method has been renamed to :meth:`set_intersection`. - - """ # noqa: W505 - return self.set_intersection(other) - - @deprecate_renamed_function("set_symmetric_difference", version="0.18.10") - def symmetric_difference(self, other: IntoExpr) -> Expr: - """ - Compute the SET SYMMETRIC DIFFERENCE between the elements in this list and the elements of `other`. - - .. deprecated:: 0.18.10 - This method has been renamed to :meth:`set_symmetric_difference`. - - """ # noqa: W505 - return self.set_symmetric_difference(other) - @deprecate_renamed_function("count_matches", version="0.19.3") def count_match(self, element: IntoExpr) -> Expr: """ diff --git a/py-polars/polars/expr/whenthen.py b/py-polars/polars/expr/whenthen.py index eb2561db288d..958fd803d835 100644 --- a/py-polars/polars/expr/whenthen.py +++ b/py-polars/polars/expr/whenthen.py @@ -9,10 +9,6 @@ parse_when_constraint_expressions, ) from polars.utils._wrap import wrap_expr -from polars.utils.deprecation import ( - deprecate_renamed_parameter, - issue_deprecation_warning, -) if TYPE_CHECKING: from polars.polars import PyExpr @@ -32,7 +28,6 @@ class When: def __init__(self, when: Any): self._when = when - @deprecate_renamed_parameter("expr", "statement", version="0.18.9") def then(self, statement: IntoExpr) -> Then: """ Attach a statement to the corresponding condition. @@ -44,9 +39,7 @@ def then(self, statement: IntoExpr) -> Then: Accepts expression input. Non-expression inputs are parsed as literals. """ - if isinstance(statement, str): - _warn_for_deprecated_string_input_behavior(statement) - statement_pyexpr = parse_as_expression(statement, str_as_lit=True) + statement_pyexpr = parse_as_expression(statement) return Then(self._when.then(statement_pyexpr)) @@ -69,7 +62,6 @@ def _from_pyexpr(cls, pyexpr: PyExpr) -> Expr: # type: ignore[override] def _pyexpr(self) -> PyExpr: return self._then.otherwise(F.lit(None)._pyexpr) - @deprecate_renamed_parameter("predicate", "condition", version="0.18.9") def when( self, *predicates: IntoExpr | Iterable[IntoExpr], @@ -93,7 +85,6 @@ def when( condition_pyexpr = parse_when_constraint_expressions(*predicates, **constraints) return ChainedWhen(self._then.when(condition_pyexpr)) - @deprecate_renamed_parameter("expr", "statement", version="0.18.9") def otherwise(self, statement: IntoExpr) -> Expr: """ Define a default for the `when-then-otherwise` expression. @@ -105,9 +96,7 @@ def otherwise(self, statement: IntoExpr) -> Expr: Accepts expression input. Non-expression inputs are parsed as literals. """ - if isinstance(statement, str): - _warn_for_deprecated_string_input_behavior(statement) - statement_pyexpr = parse_as_expression(statement, str_as_lit=True) + statement_pyexpr = parse_as_expression(statement) return wrap_expr(self._then.otherwise(statement_pyexpr)) @@ -124,7 +113,6 @@ class ChainedWhen(Expr): def __init__(self, chained_when: Any): self._chained_when = chained_when - @deprecate_renamed_parameter("expr", "statement", version="0.18.9") def then(self, statement: IntoExpr) -> ChainedThen: """ Attach a statement to the corresponding condition. @@ -136,9 +124,7 @@ def then(self, statement: IntoExpr) -> ChainedThen: Accepts expression input. Non-expression inputs are parsed as literals. """ - if isinstance(statement, str): - _warn_for_deprecated_string_input_behavior(statement) - statement_pyexpr = parse_as_expression(statement, str_as_lit=True) + statement_pyexpr = parse_as_expression(statement) return ChainedThen(self._chained_when.then(statement_pyexpr)) @@ -161,7 +147,6 @@ def _from_pyexpr(cls, pyexpr: PyExpr) -> Expr: # type: ignore[override] def _pyexpr(self) -> PyExpr: return self._chained_then.otherwise(F.lit(None)._pyexpr) - @deprecate_renamed_parameter("predicate", "condition", version="0.18.9") def when( self, *predicates: IntoExpr | Iterable[IntoExpr], @@ -185,7 +170,6 @@ def when( condition_pyexpr = parse_when_constraint_expressions(*predicates, **constraints) return ChainedWhen(self._chained_then.when(condition_pyexpr)) - @deprecate_renamed_parameter("expr", "statement", version="0.18.9") def otherwise(self, statement: IntoExpr) -> Expr: """ Define a default for the `when-then-otherwise` expression. @@ -197,15 +181,5 @@ def otherwise(self, statement: IntoExpr) -> Expr: Accepts expression input. Non-expression inputs are parsed as literals. """ - if isinstance(statement, str): - _warn_for_deprecated_string_input_behavior(statement) - statement_pyexpr = parse_as_expression(statement, str_as_lit=True) + statement_pyexpr = parse_as_expression(statement) return wrap_expr(self._chained_then.otherwise(statement_pyexpr)) - - -def _warn_for_deprecated_string_input_behavior(input: str) -> None: - issue_deprecation_warning( - "in a future version, string input will be parsed as a column name rather than a string literal." - f" To silence this warning, pass the input as an expression instead: `pl.lit({input!r})`", - version="0.18.9", - ) diff --git a/py-polars/polars/functions/__init__.py b/py-polars/polars/functions/__init__.py index 2f625cfa721f..5e76b9219698 100644 --- a/py-polars/polars/functions/__init__.py +++ b/py-polars/polars/functions/__init__.py @@ -33,7 +33,6 @@ arctan2d, arg_sort_by, arg_where, - avg, coalesce, collect_all, collect_all_async, @@ -122,7 +121,6 @@ "arctan2", "arctan2d", "arg_sort_by", - "avg", "coalesce", "col", "collect_all", diff --git a/py-polars/polars/functions/lazy.py b/py-polars/polars/functions/lazy.py index af5ea0095171..83c81e0de5a1 100644 --- a/py-polars/polars/functions/lazy.py +++ b/py-polars/polars/functions/lazy.py @@ -12,11 +12,7 @@ parse_as_list_of_expressions, ) from polars.utils._wrap import wrap_df, wrap_expr -from polars.utils.deprecation import ( - deprecate_renamed_function, - deprecate_renamed_parameter, - issue_deprecation_warning, -) +from polars.utils.deprecation import deprecate_renamed_function with contextlib.suppress(ImportError): # Module not available when building docs import polars.polars as plr @@ -79,36 +75,23 @@ def element() -> Expr: return F.col("") -@overload -def count(column: str) -> Expr: - ... - - -@overload -def count(column: Series) -> int: - ... - - -@overload -def count(column: None = None) -> Expr: - ... - - -def count(column: str | Series | None = None) -> Expr | int: +def count(column: str | None = None) -> Expr: """ Count the number of values in this column/context. + This function has different behavior depending on the input type: + + - `None` -> Expression to count the number of values in this context. + - `str` -> Syntactic sugar for `pl.col(column).count()`. + .. warning:: `null` is deemed a value in this context. Parameters ---------- column - If dtype is: - - * `pl.Series` : count the values in the Series. - * `str` : count the values in this column. - * `None` : count the number of values in this context. + Column name. If set to `None` (default), returns an expression to take the first + column of the context instead. Examples -------- @@ -137,12 +120,6 @@ def count(column: str | Series | None = None) -> Expr | int: if column is None: return wrap_expr(plr.count()) - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `count` is deprecated. Use `Series.len()` instead.", - version="0.18.8", - ) - return column.len() return F.col(column).count() @@ -150,33 +127,27 @@ def implode(name: str) -> Expr: """ Aggregate all column values into a list. + This function is syntactic sugar for `pl.col(name).implode()`. + Parameters ---------- name - Name of the column that should be imploded. + Column name. """ return F.col(name).implode() -@overload def std(column: str, ddof: int = 1) -> Expr: - ... - - -@overload -def std(column: Series, ddof: int = 1) -> float | None: - ... - - -def std(column: str | Series, ddof: int = 1) -> Expr | float | None: """ Get the standard deviation. + This function is syntactic sugar for `pl.col(column).std(ddof)`. + Parameters ---------- column - Column to get the standard deviation from. + Column name. ddof “Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements. @@ -198,33 +169,19 @@ def std(column: str | Series, ddof: int = 1) -> Expr | float | None: 3.605551275463989 """ - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `std` is deprecated. Use `Series.std()` instead.", - version="0.18.8", - ) - return column.std(ddof) return F.col(column).std(ddof) -@overload def var(column: str, ddof: int = 1) -> Expr: - ... - - -@overload -def var(column: Series, ddof: int = 1) -> float | None: - ... - - -def var(column: str | Series, ddof: int = 1) -> Expr | float | None: """ Get the variance. + This function is syntactic sugar for `pl.col(column).var(ddof)`. + Parameters ---------- column - Column to get the variance of. + Column name. ddof “Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements. @@ -246,74 +203,24 @@ def var(column: str | Series, ddof: int = 1) -> Expr | float | None: 13.0 """ - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `var` is deprecated. Use `Series.var()` instead.", - version="0.18.8", - ) - return column.var(ddof) return F.col(column).var(ddof) -@overload def mean(column: str) -> Expr: - ... - - -@overload -def mean(column: Series) -> float: - ... - - -def mean(column: str | Series) -> Expr | float | None: """ Get the mean value. - Examples - -------- - >>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2], "c": ["foo", "bar", "foo"]}) - >>> df.select(pl.mean("a")) - shape: (1, 1) - ┌─────┐ - │ a │ - │ --- │ - │ f64 │ - ╞═════╡ - │ 4.0 │ - └─────┘ + This function is syntactic sugar for `pl.col(column).mean()`. - """ - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `mean` is deprecated. Use `Series.mean()` instead.", - version="0.18.8", - ) - return column.mean() - return F.col(column).mean() - - -@overload -def avg(column: str) -> Expr: - ... - - -@overload -def avg(column: Series) -> float: - ... - - -@deprecate_renamed_function("mean", version="0.18.12") -def avg(column: str | Series) -> Expr | float: - """ - Alias for mean. - - .. deprecated:: 0.18.12 - Use `mean` instead. + Parameters + ---------- + column + Column name. Examples -------- >>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2], "c": ["foo", "bar", "foo"]}) - >>> df.select(pl.avg("a")) # doctest: +SKIP + >>> df.select(pl.mean("a")) shape: (1, 1) ┌─────┐ │ a │ @@ -324,23 +231,15 @@ def avg(column: str | Series) -> Expr | float: └─────┘ """ - return mean(column) + return F.col(column).mean() -@overload def median(column: str) -> Expr: - ... - - -@overload -def median(column: Series) -> float | int: - ... - - -def median(column: str | Series) -> Expr | float | int | None: """ Get the median value. + This function is syntactic sugar for `pl.col(column).median()`. + Examples -------- >>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2], "c": ["foo", "bar", "foo"]}) @@ -355,29 +254,20 @@ def median(column: str | Series) -> Expr | float | int | None: └─────┘ """ - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `median` is deprecated. Use `Series.median()` instead.", - version="0.18.8", - ) - return column.median() return F.col(column).median() -@overload def n_unique(column: str) -> Expr: - ... - - -@overload -def n_unique(column: Series) -> int: - ... - - -def n_unique(column: str | Series) -> Expr | int: """ Count unique values. + This function is syntactic sugar for `pl.col(column).n_unique()`. + + Parameters + ---------- + column + Column name. + Examples -------- >>> df = pl.DataFrame({"a": [1, 8, 1], "b": [4, 5, 2], "c": ["foo", "bar", "foo"]}) @@ -392,12 +282,6 @@ def n_unique(column: str | Series) -> Expr | int: └─────┘ """ - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `n_unique` is deprecated. Use `Series.n_unique()` instead.", - version="0.18.8", - ) - return column.n_unique() return F.col(column).n_unique() @@ -410,7 +294,7 @@ def approx_n_unique(column: str | Expr) -> Expr: Parameters ---------- column - Column name or Series. + Column name. Examples -------- @@ -431,32 +315,20 @@ def approx_n_unique(column: str | Expr) -> Expr: return F.col(column).approx_n_unique() -@overload -def first(column: str) -> Expr: - ... - - -@overload -def first(column: Series) -> Any: - ... - - -@overload -def first(column: None = None) -> Expr: - ... - - -def first(column: str | Series | None = None) -> Expr | Any: +def first(column: str | None = None) -> Expr: """ Get the first value. - Depending on the input type this function does different things: + This function has different behavior depending on the input type: - input: + - `None` -> Expression to take first column of a context. + - `str` -> Syntactic sugar for `pl.col(column).first()`. - - None -> expression to take first column of a context. - - str -> syntactic sugar for `pl.col(..).first()` - - Series -> Take first value in `Series` + Parameters + ---------- + column + Column name. If set to `None` (default), returns an expression to take the first + column of the context instead. Examples -------- @@ -486,42 +358,23 @@ def first(column: str | Series | None = None) -> Expr | Any: if column is None: return wrap_expr(plr.first()) - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `first` is deprecated. Use `series[0]` instead.", - version="0.18.8", - ) - if column.len() > 0: - return column[0] - else: - raise IndexError("the Series is empty, so no first value can be returned") return F.col(column).first() -@overload -def last(column: str) -> Expr: - ... - - -@overload -def last(column: Series) -> Any: - ... - - -@overload -def last(column: None = None) -> Expr: - ... - - -def last(column: str | Series | None = None) -> Expr: +def last(column: str | None = None) -> Expr: """ Get the last value. - Depending on the input type this function does different things: + This function has different behavior depending on the input type: + + - `None` -> Expression to take last column of a context. + - `str` -> Syntactic sugar for `pl.col(column).last()`. - - None -> expression to take last column of a context. - - str -> syntactic sugar for `pl.col(..).last()` - - Series -> Take last value in `Series` + Parameters + ---------- + column + Column name. If set to `None` (default), returns an expression to take the last + column of the context instead. Examples -------- @@ -551,36 +404,19 @@ def last(column: str | Series | None = None) -> Expr: if column is None: return wrap_expr(plr.last()) - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `last` is deprecated. Use `series[-1]` instead.", - version="0.18.8", - ) - if column.len() > 0: - return column[-1] - else: - raise IndexError("the Series is empty, so no last value can be returned") return F.col(column).last() -@overload -def head(column: str, n: int = ...) -> Expr: - ... - - -@overload -def head(column: Series, n: int = ...) -> Series: - ... - - -def head(column: str | Series, n: int = 10) -> Expr | Series: +def head(column: str, n: int = 10) -> Expr: """ Get the first `n` rows. + This function is syntactic sugar for `pl.col(column).head(n)`. + Parameters ---------- column - Column name or Series. + Column name. n Number of rows to return. @@ -610,33 +446,19 @@ def head(column: str | Series, n: int = 10) -> Expr | Series: └─────┘ """ - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `head` is deprecated. Use `Series.head()` instead.", - version="0.18.8", - ) - return column.head(n) return F.col(column).head(n) -@overload -def tail(column: str, n: int = ...) -> Expr: - ... - - -@overload -def tail(column: Series, n: int = ...) -> Series: - ... - - -def tail(column: str | Series, n: int = 10) -> Expr | Series: +def tail(column: str, n: int = 10) -> Expr: """ Get the last `n` rows. + This function is syntactic sugar for `pl.col(column).tail(n)`. + Parameters ---------- column - Column name or Series. + Column name. n Number of rows to return. @@ -666,12 +488,6 @@ def tail(column: str | Series, n: int = 10) -> Expr | Series: └─────┘ """ - if isinstance(column, pl.Series): - issue_deprecation_warning( - "passing a Series to `tail` is deprecated. Use `Series.tail()` instead.", - version="0.18.8", - ) - return column.tail(n) return F.col(column).tail(n) @@ -1538,9 +1354,6 @@ def arg_sort_by( return wrap_expr(plr.arg_sort_by(exprs, descending)) -@deprecate_renamed_parameter( - "common_subplan_elimination", "comm_subplan_elim", version="0.18.9" -) def collect_all( lazy_frames: Iterable[LazyFrame], *, diff --git a/py-polars/polars/functions/range/date_range.py b/py-polars/polars/functions/range/date_range.py index 7880580856b6..42abc7dc1a2f 100644 --- a/py-polars/polars/functions/range/date_range.py +++ b/py-polars/polars/functions/range/date_range.py @@ -9,7 +9,6 @@ from polars.utils._parse_expr_input import parse_as_expression from polars.utils._wrap import wrap_expr from polars.utils.deprecation import ( - deprecate_renamed_parameter, deprecate_saturating, issue_deprecation_warning, ) @@ -35,7 +34,6 @@ def date_range( time_unit: TimeUnit | None = ..., time_zone: str | None = ..., eager: Literal[False] = ..., - name: str | None = ..., ) -> Expr: ... @@ -50,7 +48,6 @@ def date_range( time_unit: TimeUnit | None = ..., time_zone: str | None = ..., eager: Literal[True], - name: str | None = ..., ) -> Series: ... @@ -65,13 +62,10 @@ def date_range( time_unit: TimeUnit | None = ..., time_zone: str | None = ..., eager: bool, - name: str | None = ..., ) -> Series | Expr: ... -@deprecate_renamed_parameter("low", "start", version="0.18.0") -@deprecate_renamed_parameter("high", "end", version="0.18.0") def date_range( start: date | datetime | IntoExprColumn, end: date | datetime | IntoExprColumn, @@ -81,7 +75,6 @@ def date_range( time_unit: TimeUnit | None = None, time_zone: str | None = None, eager: bool = False, - name: str | None = None, ) -> Series | Expr: """ Generate a date range. @@ -106,11 +99,6 @@ def date_range( eager Evaluate immediately and return a `Series`. If set to `False` (default), return an expression instead. - name - Name of the output column. - - .. deprecated:: 0.18.0 - This argument is deprecated. Use the `alias` method instead. Returns ------- @@ -183,11 +171,6 @@ def date_range( """ interval = deprecate_saturating(interval) - if name is not None: - issue_deprecation_warning( - "the `name` argument is deprecated. Use the `alias` method instead.", - version="0.18.0", - ) interval = parse_interval_argument(interval) if time_unit is None and "ns" in interval: @@ -201,9 +184,6 @@ def date_range( plr.date_range(start_pyexpr, end_pyexpr, interval, closed, time_unit, time_zone) ) - if name is not None: - result = result.alias(name) - if eager: return F.select(result).to_series() diff --git a/py-polars/polars/functions/range/time_range.py b/py-polars/polars/functions/range/time_range.py index 8415231c08c5..2a22b207c10c 100644 --- a/py-polars/polars/functions/range/time_range.py +++ b/py-polars/polars/functions/range/time_range.py @@ -8,7 +8,7 @@ from polars.functions.range._utils import parse_interval_argument from polars.utils._parse_expr_input import parse_as_expression from polars.utils._wrap import wrap_expr -from polars.utils.deprecation import deprecate_saturating, issue_deprecation_warning +from polars.utils.deprecation import deprecate_saturating with contextlib.suppress(ImportError): # Module not available when building docs import polars.polars as plr @@ -29,7 +29,6 @@ def time_range( *, closed: ClosedInterval = ..., eager: Literal[False] = ..., - name: str | None = ..., ) -> Expr: ... @@ -42,7 +41,6 @@ def time_range( *, closed: ClosedInterval = ..., eager: Literal[True], - name: str | None = ..., ) -> Series: ... @@ -55,7 +53,6 @@ def time_range( *, closed: ClosedInterval = ..., eager: bool, - name: str | None = ..., ) -> Series | Expr: ... @@ -67,7 +64,6 @@ def time_range( *, closed: ClosedInterval = "both", eager: bool = False, - name: str | None = None, ) -> Series | Expr: """ Generate a time range. @@ -88,11 +84,6 @@ def time_range( eager Evaluate immediately and return a `Series`. If set to `False` (default), return an expression instead. - name - Name of the output column. - - .. deprecated:: 0.18.0 - This argument is deprecated. Use the `alias` method instead. Returns ------- @@ -145,11 +136,6 @@ def time_range( """ interval = deprecate_saturating(interval) - if name is not None: - issue_deprecation_warning( - "the `name` argument is deprecated. Use the `alias` method instead.", - version="0.18.0", - ) interval = parse_interval_argument(interval) for unit in ("y", "mo", "w", "d"): @@ -166,9 +152,6 @@ def time_range( result = wrap_expr(plr.time_range(start_pyexpr, end_pyexpr, interval, closed)) - if name is not None: - result = result.alias(name) - if eager: return F.select(result).to_series() diff --git a/py-polars/polars/functions/repeat.py b/py-polars/polars/functions/repeat.py index dade846ed126..e2249ca43750 100644 --- a/py-polars/polars/functions/repeat.py +++ b/py-polars/polars/functions/repeat.py @@ -7,7 +7,6 @@ from polars.datatypes import Float64 from polars.utils._parse_expr_input import parse_as_expression from polars.utils._wrap import wrap_expr -from polars.utils.deprecation import issue_deprecation_warning with contextlib.suppress(ImportError): # Module not available when building docs import polars.polars as plr @@ -27,7 +26,6 @@ def repeat( *, dtype: PolarsDataType | None = ..., eager: Literal[False] = ..., - name: str | None = ..., ) -> Expr: ... @@ -39,7 +37,6 @@ def repeat( *, dtype: PolarsDataType | None = ..., eager: Literal[True], - name: str | None = ..., ) -> Series: ... @@ -51,7 +48,6 @@ def repeat( *, dtype: PolarsDataType | None = ..., eager: bool, - name: str | None = ..., ) -> Expr | Series: ... @@ -62,7 +58,6 @@ def repeat( *, dtype: PolarsDataType | None = None, eager: bool = False, - name: str | None = None, ) -> Expr | Series: """ Construct a column of length `n` filled with the given value. @@ -80,11 +75,6 @@ def repeat( eager Evaluate immediately and return a `Series`. If set to `False` (default), return an expression instead. - name - Name of the resulting column. - - .. deprecated:: 0.17.15 - This argument is deprecated. Use the `alias` method instead. Notes ----- @@ -120,18 +110,10 @@ def repeat( ] """ - if name is not None: - issue_deprecation_warning( - "the `name` argument is deprecated. Use the `alias` method instead.", - version="0.18.0", - ) - if isinstance(n, int): n = F.lit(n) value = parse_as_expression(value, str_as_lit=True) expr = wrap_expr(plr.repeat(value, n._pyexpr, dtype)) - if name is not None: - expr = expr.alias(name) if eager: return F.select(expr).to_series() return expr diff --git a/py-polars/polars/functions/whenthen.py b/py-polars/polars/functions/whenthen.py index 3f5e197dd5de..e83fdf613efa 100644 --- a/py-polars/polars/functions/whenthen.py +++ b/py-polars/polars/functions/whenthen.py @@ -5,7 +5,6 @@ import polars._reexport as pl from polars.utils._parse_expr_input import parse_when_constraint_expressions -from polars.utils.deprecation import deprecate_renamed_parameter with contextlib.suppress(ImportError): # Module not available when building docs import polars.polars as plr @@ -14,7 +13,6 @@ from polars.type_aliases import IntoExprColumn -@deprecate_renamed_parameter("expr", "condition", version="0.18.9") def when( *predicates: IntoExprColumn | Iterable[IntoExprColumn] | bool, **constraints: Any, diff --git a/py-polars/polars/lazyframe/frame.py b/py-polars/polars/lazyframe/frame.py index 5264f671ccb0..90933de2ec54 100644 --- a/py-polars/polars/lazyframe/frame.py +++ b/py-polars/polars/lazyframe/frame.py @@ -584,55 +584,6 @@ def _scan_python_function( ) return self - @classmethod - @deprecate_function( - "Convert the JSON string to `StringIO` and then use `LazyFrame.deserialize`.", - version="0.18.12", - ) - def from_json(cls, json: str) -> Self: - """ - Read a logical plan from a JSON string to construct a LazyFrame. - - .. deprecated:: 0.18.12 - This method is deprecated. Convert the JSON string to `StringIO` - and then use `LazyFrame.deserialize`. - - Parameters - ---------- - json - String in JSON format. - - See Also - -------- - deserialize - - """ - return cls.deserialize(StringIO(json)) - - @classmethod - @deprecate_renamed_function("deserialize", version="0.18.12") - @deprecate_renamed_parameter("file", "source", version="0.18.12") - def read_json(cls, source: str | Path | IOBase) -> Self: - """ - Read a logical plan from a JSON file to construct a LazyFrame. - - .. deprecated:: 0.18.12 - This class method has been renamed to :meth:`deserialize`. - - Parameters - ---------- - source - Path to a file or a file-like object (by file-like object, we refer to - objects that have a `read()` method, such as a file handler (e.g. - via builtin `open` function) or `BytesIO`). - - See Also - -------- - deserialize - - """ - return cls.deserialize(source) - @classmethod def deserialize(cls, source: str | Path | IOBase) -> Self: """ @@ -914,30 +865,6 @@ def serialize(self, file: IOBase | str | Path | None = None) -> str | None: self._ldf.serialize(file) return None - @overload - def write_json(self, file: None = ...) -> str: - ... - - @overload - def write_json(self, file: IOBase | str | Path) -> None: - ... - - @deprecate_renamed_function("serialize", version="0.18.12") - def write_json(self, file: IOBase | str | Path | None = None) -> str | None: - """ - Serialize the logical plan of this LazyFrame to a file or string in JSON format. - - .. deprecated:: 0.18.12 - This method has been renamed to :func:`LazyFrame.serialize`. - - Parameters - ---------- - file - File path to which the result should be written. If set to `None` - (default), the output is returned as a string instead. - """ - return self.serialize(file) - def pipe( self, function: Callable[Concatenate[LazyFrame, P], T], @@ -1011,9 +938,6 @@ def pipe( """ return function(self, *args, **kwargs) - @deprecate_renamed_parameter( - "common_subplan_elimination", "comm_subplan_elim", version="0.18.9" - ) def explain( self, *, @@ -1084,9 +1008,6 @@ def explain( return ldf.describe_optimized_plan() return self._ldf.describe_plan() - @deprecate_renamed_parameter( - "common_subplan_elimination", "comm_subplan_elim", version="0.18.9" - ) def show_graph( self, *, @@ -1508,9 +1429,6 @@ def bottom_k( self._ldf.bottom_k(k, by, descending, nulls_last, maintain_order) ) - @deprecate_renamed_parameter( - "common_subplan_elimination", "comm_subplan_elim", version="0.18.9" - ) def profile( self, *, @@ -1661,9 +1579,6 @@ def profile( return df, timings - @deprecate_renamed_parameter( - "common_subplan_elimination", "comm_subplan_elim", version="0.18.9" - ) def collect( self, *, @@ -2329,9 +2244,6 @@ def _set_sink_optimizations( _eager=False, ) - @deprecate_renamed_parameter( - "common_subplan_elimination", "comm_subplan_elim", version="0.18.9" - ) def fetch( self, n_rows: int = 500, @@ -4641,17 +4553,6 @@ def approx_n_unique(self) -> Self: """ return self.select(F.all().approx_n_unique()) - @deprecate_renamed_function("approx_n_unique", version="0.18.12") - def approx_unique(self) -> Self: - """ - Approximate count of unique values. - - .. deprecated:: 0.18.12 - This method has been renamed to :func:`LazyFrame.approx_n_unique`. - - """ - return self.approx_n_unique() - def with_row_count(self, name: str = "row_nr", offset: int = 0) -> Self: """ Add a column at index 0 that counts the rows. diff --git a/py-polars/polars/selectors.py b/py-polars/polars/selectors.py index be04c357f419..39f0fc36cc2c 100644 --- a/py-polars/polars/selectors.py +++ b/py-polars/polars/selectors.py @@ -25,7 +25,7 @@ is_polars_dtype, ) from polars.expr import Expr -from polars.utils.deprecation import deprecate_function, deprecate_nonkeyword_arguments +from polars.utils.deprecation import deprecate_nonkeyword_arguments if TYPE_CHECKING: import sys @@ -122,30 +122,6 @@ def expand_selector( return tuple(target.select(selector).columns) -@deprecate_function( - message="This function has been superseded by `expand_selector`; please update accordingly", - version="0.18.14", -) -def selector_column_names( - frame: DataFrame | LazyFrame, selector: SelectorType -) -> tuple[str, ...]: - """ - Return the column names that would be selected from the given frame. - - .. deprecated:: 0.18.14 - Use :func:`expand_selector` instead. - - Parameters - ---------- - frame - A polars DataFrame or LazyFrame. - selector - An arbitrary polars selector (or compound selector). - - """ - return expand_selector(target=frame, selector=selector) - - def _expand_selectors( frame: DataFrame | LazyFrame, items: Any, *more_items: Any ) -> list[Any]: diff --git a/py-polars/polars/series/list.py b/py-polars/polars/series/list.py index abd0c3f5cefb..5cf881b4350b 100644 --- a/py-polars/polars/series/list.py +++ b/py-polars/polars/series/list.py @@ -768,50 +768,6 @@ def set_symmetric_difference(self, other: Series) -> Series: """ # noqa: W505 - @deprecate_renamed_function("set_union", version="0.18.10") - def union(self, other: Series) -> Series: - """ - Compute the SET UNION between the elements in this list and the elements of `other`. - - .. deprecated:: 0.18.10 - This method has been renamed to :meth:`set_union`. - - """ # noqa: W505 - return self.set_union(other) - - @deprecate_renamed_function("set_difference", version="0.18.10") - def difference(self, other: Series) -> Series: - """ - Compute the SET DIFFERENCE between the elements in this list and the elements of `other`. - - .. deprecated:: 0.18.10 - This method has been renamed to :meth:`set_difference`. - - """ # noqa: W505 - return self.set_difference(other) - - @deprecate_renamed_function("set_intersection", version="0.18.10") - def intersection(self, other: Series) -> Series: - """ - Compute the SET INTERSECTION between the elements in this list and the elements of `other`. - - .. deprecated:: 0.18.10 - This method has been renamed to :meth:`set_intersection`. - - """ # noqa: W505 - return self.set_intersection(other) - - @deprecate_renamed_function("set_symmetric_difference", version="0.18.10") - def symmetric_difference(self, other: Series) -> Series: - """ - Compute the SET SYMMETRIC DIFFERENCE between the elements in this list and the elements of `other`. - - .. deprecated:: 0.18.10 - This method has been renamed to :meth:`set_symmetric_difference`. - - """ # noqa: W505 - return self.set_symmetric_difference(other) - @deprecate_renamed_function("count_matches", version="0.19.3") def count_match( self, element: float | str | bool | int | date | datetime | time | Expr diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index cce7c84dd950..14b8e797b7e9 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -1915,7 +1915,6 @@ def cut( ... @deprecate_nonkeyword_arguments(["self", "breaks"], version="0.19.0") - @deprecate_renamed_parameter("bins", "breaks", version="0.18.8") @deprecate_renamed_parameter("series", "as_series", version="0.19.0") def cut( self, @@ -2111,8 +2110,6 @@ def qcut( ) -> Series | DataFrame: ... - @deprecate_renamed_parameter("series", "as_series", version="0.18.14") - @deprecate_renamed_parameter("q", "quantiles", version="0.18.12") def qcut( self, quantiles: Sequence[float] | int, @@ -2236,13 +2233,13 @@ def qcut( issue_deprecation_warning( "The `break_point_label` parameter for `Series.cut` will be removed." " Use `Series.struct.rename_fields` to rename the field instead.", - version="0.18.14", + version="0.19.0", ) if category_label != "category": issue_deprecation_warning( "The `category_label` parameter for `Series.cut` will be removed." " Use `Series.struct.rename_fields` to rename the field instead.", - version="0.18.14", + version="0.19.0", ) if not as_series: issue_deprecation_warning( @@ -2250,7 +2247,7 @@ def qcut( " The same behavior can be achieved by setting `include_breaks=True`," " unnesting the resulting struct Series," " and adding the result to the original Series.", - version="0.18.14", + version="0.19.0", ) temp_name = self.name + "_bin" return ( @@ -2770,42 +2767,16 @@ def slice(self, offset: int, length: int | None = None) -> Series: """ - def append(self, other: Series, *, append_chunks: bool | None = None) -> Self: + def append(self, other: Series) -> Self: """ Append a Series to this one. + The resulting series will consist of multiple chunks. + Parameters ---------- other Series to append. - append_chunks - .. deprecated:: 0.18.8 - This argument will be removed and `append` will change to always - behave like `append_chunks=True` (the previous default). For the - behavior of `append_chunks=False`, use `Series.extend`. - - If set to `True` the append operation will add the chunks from `other` to - self. This is super cheap. - - If set to `False` the append operation will do the same as - `DataFrame.extend` which extends the memory backed by this `Series` with - the values from `other`. - - Different from `append chunks`, `extend` appends the data from `other` to - the underlying memory locations and thus may cause a reallocation (which are - expensive). - - If this does not cause a reallocation, the resulting data structure will not - have any extra chunks and thus will yield faster queries. - - Prefer `extend` over `append_chunks` when you want to do a query after a - single append. For instance during online operations where you add `n` rows - and rerun a query. - - Prefer `append_chunks` over `extend` when you want to append many times - before doing a query. For instance when you read in multiple files and when - to store them in a single `Series`. In the latter case, finish the sequence - of `append_chunks` operations with a `rechunk`. Warnings -------- @@ -2837,19 +2808,6 @@ def append(self, other: Series, *, append_chunks: bool | None = None) -> Self: 2 """ - if append_chunks is not None: - issue_deprecation_warning( - "the `append_chunks` argument will be removed and `append` will change" - " to always behave like `append_chunks=True` (the previous default)." - " For the behavior of `append_chunks=False`, use `Series.extend`.", - version="0.18.8", - ) - else: - append_chunks = True - - if not append_chunks: - return self.extend(other) - try: self._s.append(other._s) except RuntimeError as exc: diff --git a/py-polars/polars/utils/deprecation.py b/py-polars/polars/utils/deprecation.py index f4f05fe74f53..3aab2afb4caa 100644 --- a/py-polars/polars/utils/deprecation.py +++ b/py-polars/polars/utils/deprecation.py @@ -214,36 +214,6 @@ def _format_argument_list(allowed_args: list[str]) -> str: return f" except for {args} and {last!r}" -def warn_closed_future_change() -> Callable[[Callable[P, T]], Callable[P, T]]: - """ - Issue a warning to specify a value for `closed` as the default value will change. - - Decorator for rolling functions. Use as follows:: - - @warn_closed_future_change() - def rolling_min(): - ... - - """ - - def decorate(function: Callable[P, T]) -> Callable[P, T]: - @wraps(function) - def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: - # we only warn if 'by' is passed in, otherwise 'closed' is not used - if (kwargs.get("by") is not None) and ("closed" not in kwargs): - issue_deprecation_warning( - "The default value for `closed` will change from 'left' to 'right' in a future version." - " Explicitly pass a value for `closed` to silence this warning.", - version="0.18.4", - ) - return function(*args, **kwargs) - - wrapper.__signature__ = inspect.signature(function) # type: ignore[attr-defined] - return wrapper - - return decorate - - def rename_use_earliest_to_ambiguous( use_earliest: bool | None, ambiguous: Ambiguous | Expr ) -> Ambiguous | Expr: diff --git a/py-polars/tests/unit/datatypes/test_temporal.py b/py-polars/tests/unit/datatypes/test_temporal.py index 4743e647fb29..da15f4232c14 100644 --- a/py-polars/tests/unit/datatypes/test_temporal.py +++ b/py-polars/tests/unit/datatypes/test_temporal.py @@ -2741,6 +2741,6 @@ def test_rolling_duplicates() -> None: "value": [0, 1], } ) - assert df.sort("ts").with_columns( - pl.col("value").rolling_max("1d", by="ts", closed="right") - )["value"].to_list() == [1, 1] + assert df.sort("ts").with_columns(pl.col("value").rolling_max("1d", by="ts"))[ + "value" + ].to_list() == [1, 1] diff --git a/py-polars/tests/unit/functions/range/test_date_range.py b/py-polars/tests/unit/functions/range/test_date_range.py index a8ce8ccf0c28..1a6df83decf2 100644 --- a/py-polars/tests/unit/functions/range/test_date_range.py +++ b/py-polars/tests/unit/functions/range/test_date_range.py @@ -199,19 +199,6 @@ def test_date_range_eager() -> None: assert_series_equal(result, expected) -def test_deprecated_name_arg() -> None: - name = "x" - with pytest.deprecated_call(): - result_lazy = pl.date_range(date(2023, 1, 1), date(2023, 1, 3), name=name) - assert result_lazy.meta.output_name() == name - - with pytest.deprecated_call(): - result_eager = pl.date_range( - date(2023, 1, 1), date(2023, 1, 3), name=name, eager=True - ) - assert result_eager.name == name - - @pytest.mark.parametrize( ( "input_time_unit", diff --git a/py-polars/tests/unit/functions/range/test_time_range.py b/py-polars/tests/unit/functions/range/test_time_range.py index 5bc49bce204f..60f7482f05b5 100644 --- a/py-polars/tests/unit/functions/range/test_time_range.py +++ b/py-polars/tests/unit/functions/range/test_time_range.py @@ -242,15 +242,3 @@ def test_time_range_name() -> None: result_lazy = pl.select(pl.time_range(time(10), time(12), eager=False)).to_series() assert result_lazy.name == expected_name - - -def test_deprecated_name_arg() -> None: - name = "x" - - with pytest.deprecated_call(): - result_lazy = pl.time_range(time(10), time(12), name=name) - assert result_lazy.meta.output_name() == name - - with pytest.deprecated_call(): - result_eager = pl.time_range(time(10), time(12), name=name, eager=True) - assert result_eager.name == name diff --git a/py-polars/tests/unit/functions/test_functions.py b/py-polars/tests/unit/functions/test_functions.py index b157a8978733..05c5b6495a6f 100644 --- a/py-polars/tests/unit/functions/test_functions.py +++ b/py-polars/tests/unit/functions/test_functions.py @@ -358,8 +358,6 @@ def test_lazy_functions() -> None: df = pl.DataFrame({"a": ["foo", "bar", "2"], "b": [1, 2, 3], "c": [1.0, 2.0, 3.0]}) out = df.select(pl.count("a")) assert list(out["a"]) == [3] - with pytest.deprecated_call(): - assert pl.count(df["a"]) == 3 out = df.select( [ pl.var("b").alias("1"), @@ -428,16 +426,10 @@ def test_lazy_functions() -> None: def test_head_tail(fruits_cars: pl.DataFrame) -> None: - res_expr = fruits_cars.select([pl.head("A", 2)]) - with pytest.deprecated_call(): - res_series = pl.head(fruits_cars["A"], 2) + res_expr = fruits_cars.select(pl.head("A", 2)) expected = pl.Series("A", [1, 2]) - assert_series_equal(res_expr.to_series(0), expected) - assert_series_equal(res_series, expected) + assert_series_equal(res_expr.to_series(), expected) - res_expr = fruits_cars.select([pl.tail("A", 2)]) - with pytest.deprecated_call(): - res_series = pl.tail(fruits_cars["A"], 2) + res_expr = fruits_cars.select(pl.tail("A", 2)) expected = pl.Series("A", [4, 5]) - assert_series_equal(res_expr.to_series(0), expected) - assert_series_equal(res_series, expected) + assert_series_equal(res_expr.to_series(), expected) diff --git a/py-polars/tests/unit/functions/test_whenthen.py b/py-polars/tests/unit/functions/test_whenthen.py index ad4ecb7cb5bd..42dcf0c17fa7 100644 --- a/py-polars/tests/unit/functions/test_whenthen.py +++ b/py-polars/tests/unit/functions/test_whenthen.py @@ -3,7 +3,7 @@ import pytest import polars as pl -from polars.testing import assert_frame_equal, assert_series_equal +from polars.testing import assert_frame_equal def test_when_then() -> None: @@ -242,22 +242,6 @@ def test_comp_categorical_lit_dtype() -> None: ).dtypes == [pl.Categorical, pl.Int32] -def test_when_then_deprecated_string_input() -> None: - df = pl.DataFrame( - { - "a": [True, False], - "b": [1, 2], - "c": [3, 4], - } - ) - - with pytest.deprecated_call(): - result = df.select(pl.when("a").then("b").otherwise("c").alias("when")) - - expected = pl.Series("when", ["b", "c"]) - assert_series_equal(result.to_series(), expected) - - def test_predicate_broadcast() -> None: df = pl.DataFrame( { @@ -502,13 +486,6 @@ def test_when_then_binary_op_predicate_agg_12526() -> None: assert_frame_equal(expect, actual) -def test_when_then_deprecation() -> None: - df = pl.DataFrame({"foo": [5, 4, 3], "bar": [2, 1, 0]}) - for param_name in ("expr", "condition"): - with pytest.warns(DeprecationWarning, match="pass as a positional argument"): - df.select(pl.when(**{param_name: pl.col("bar") >= 0}).then(99)) - - def test_when_predicates_kwargs() -> None: df = pl.DataFrame( { diff --git a/py-polars/tests/unit/operations/rolling/test_rolling.py b/py-polars/tests/unit/operations/rolling/test_rolling.py index 05c96f978e99..cf39b2dccd13 100644 --- a/py-polars/tests/unit/operations/rolling/test_rolling.py +++ b/py-polars/tests/unit/operations/rolling/test_rolling.py @@ -618,9 +618,7 @@ def test_rolling_aggregations_unsorted_raise_10991() -> None: with pytest.warns( UserWarning, match="Series is not known to be sorted by `by` column." ): - _ = df.with_columns( - roll=pl.col("val").rolling_sum("2d", by="dt", closed="right") - ) + df.with_columns(roll=pl.col("val").rolling_sum("2d", by="dt")) def test_rolling_aggregations_with_over_11225() -> None: @@ -733,9 +731,7 @@ def test_rolling_by_date() -> None: } ).sort("dt") - result = df.with_columns( - roll=pl.col("val").rolling_sum("2d", by="dt", closed="right") - ) + result = df.with_columns(roll=pl.col("val").rolling_sum("2d", by="dt")) expected = df.with_columns(roll=pl.Series([1, 3, 5])) assert_frame_equal(result, expected) @@ -752,9 +748,7 @@ def test_rolling_nanoseconds_11003() -> None: } ) df = df.with_columns(pl.col("dt").str.to_datetime(time_unit="ns")).set_sorted("dt") - result = df.with_columns( - pl.col("val").rolling_sum("500ns", by="dt", closed="right") - ) + result = df.with_columns(pl.col("val").rolling_sum("500ns", by="dt")) expected = df.with_columns(val=pl.Series([1, 3, 6])) assert_frame_equal(result, expected) diff --git a/py-polars/tests/unit/series/test_append.py b/py-polars/tests/unit/series/test_append.py index 6d08e9e0ec30..45e91dd012f5 100644 --- a/py-polars/tests/unit/series/test_append.py +++ b/py-polars/tests/unit/series/test_append.py @@ -16,18 +16,6 @@ def test_append() -> None: assert a.n_chunks() == 2 -def test_append_deprecated_append_chunks() -> None: - a = pl.Series("a", [1, 2]) - b = pl.Series("b", [8, 9, None]) - - with pytest.deprecated_call(): - a.append(b, append_chunks=False) - - expected = pl.Series("a", [1, 2, 8, 9, None]) - assert_series_equal(a, expected) - assert a.n_chunks() == 1 - - def test_append_self_3915() -> None: a = pl.Series("a", [1, 2]) diff --git a/py-polars/tests/unit/test_serde.py b/py-polars/tests/unit/test_serde.py index 17caef9601e4..6a733b791196 100644 --- a/py-polars/tests/unit/test_serde.py +++ b/py-polars/tests/unit/test_serde.py @@ -32,20 +32,6 @@ def test_lazyframe_serde() -> None: assert_series_equal(result.collect().to_series(), pl.Series("a", [1, 2, 3])) -def test_lazyframe_deprecated_serde() -> None: - lf = pl.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}).lazy().select(pl.col("a")) - - with pytest.deprecated_call(): - json = lf.write_json() - with pytest.deprecated_call(): - result_from = pl.LazyFrame.from_json(json) - with pytest.deprecated_call(): - result_read = pl.LazyFrame.read_json(io.StringIO(json)) - - assert_series_equal(result_from.collect().to_series(), pl.Series("a", [1, 2, 3])) - assert_series_equal(result_read.collect().to_series(), pl.Series("a", [1, 2, 3])) - - def test_serde_time_unit() -> None: assert pickle.loads( pickle.dumps( diff --git a/py-polars/tests/unit/utils/test_deprecation.py b/py-polars/tests/unit/utils/test_deprecation.py index 998e5937a813..fee0a18724b6 100644 --- a/py-polars/tests/unit/utils/test_deprecation.py +++ b/py-polars/tests/unit/utils/test_deprecation.py @@ -11,7 +11,6 @@ deprecate_renamed_function, deprecate_renamed_parameter, issue_deprecation_warning, - warn_closed_future_change, ) @@ -72,30 +71,3 @@ def test_deprecate_nonkeyword_arguments_method_warning() -> None: ) with pytest.deprecated_call(match=msg): Foo().bar("qux", "quox") - - -def test_warn_closed_future_change() -> None: - @warn_closed_future_change() - def rolling_test(by: str | None = None, closed: str = "left") -> None: - ... - - # If we pass `by` but not `closed`, we expect a warning - with pytest.deprecated_call(): - rolling_test(by="b") - - -def test_warn_closed_future_change_no_warning(recwarn: Any) -> None: - @warn_closed_future_change() - def rolling_test(by: str | None = None, closed: str = "left") -> None: - ... - - # No warning if we do not pass `by` - rolling_test() - - # If we pass `by` and `closed`, we expect no warning... - rolling_test(by="b", closed="left") - - # ... regardless of the value - rolling_test(by="b", closed="right") - - assert len(recwarn) == 0