From 1f51fa31365fd765c5fd035e4598fe870957bcb1 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Fri, 20 Oct 2023 21:57:49 +0200 Subject: [PATCH] Deprecate ordering --- py-polars/polars/datatypes/classes.py | 24 ++++++++++++++++---- py-polars/tests/unit/datatypes/test_array.py | 11 +++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/py-polars/polars/datatypes/classes.py b/py-polars/polars/datatypes/classes.py index 0ded0b7c548b..6c9acf5a5f63 100644 --- a/py-polars/polars/datatypes/classes.py +++ b/py-polars/polars/datatypes/classes.py @@ -523,8 +523,11 @@ class Array(NestedType): inner: PolarsDataType | None = None width: int - def __init__( - self, width: int, inner: PolarsDataType | PythonDataType | None = None + def __init__( # noqa: D417 + self, + *args: Any, + width: int | None = None, + inner: PolarsDataType | PythonDataType | None = None, ): """ Fixed length list type. @@ -550,9 +553,22 @@ def __init__( ] """ - if inner is None: - from polars.utils.deprecation import issue_deprecation_warning + from polars.utils.deprecation import issue_deprecation_warning + if args: + issue_deprecation_warning( + "Parameters `inner` and `width` will change positions in the next breaking release." + " Use keyword arguments to keep current behavior and silence this warning.", + version="0.19.11", + ) + if len(args) == 1: + width = args[0] + else: + width, inner = args[:2] + elif width is None: + raise TypeError("`width` must be specified when initializing an `Array`") + + if inner is None: issue_deprecation_warning( "The default value for the `inner` parameter of `Array` will be removed in the next breaking release." " Pass `inner=pl.Null`to keep current behavior and silence this warning.", diff --git a/py-polars/tests/unit/datatypes/test_array.py b/py-polars/tests/unit/datatypes/test_array.py index 2786c693531b..fc4064addbb6 100644 --- a/py-polars/tests/unit/datatypes/test_array.py +++ b/py-polars/tests/unit/datatypes/test_array.py @@ -104,3 +104,14 @@ def test_array_concat() -> None: assert pl.concat([a_df, b_df]).to_dict(False) == { "a": [[0, 1], [1, 0], [1, 1], [0, 0]] } + + +def test_array_init_deprecation() -> None: + with pytest.deprecated_call(): + pl.Array(2) + with pytest.deprecated_call(): + pl.Array(2, pl.Utf8) + with pytest.deprecated_call(): + pl.Array(2, inner=pl.Utf8) + with pytest.deprecated_call(): + pl.Array(width=2)