Skip to content

Commit

Permalink
Deprecate ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Oct 20, 2023
1 parent 6ebe19b commit 1f51fa3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
24 changes: 20 additions & 4 deletions py-polars/polars/datatypes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.",
Expand Down
11 changes: 11 additions & 0 deletions py-polars/tests/unit/datatypes/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1f51fa3

Please sign in to comment.