Skip to content

Commit

Permalink
undo warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Oct 26, 2024
1 parent 372a8b4 commit c9197aa
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 51 deletions.
33 changes: 1 addition & 32 deletions py-polars/polars/expr/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,7 @@ def to_struct(
self,
n_field_strategy: ListToStructWidthStrategy = "first_non_null",
fields: Sequence[str] | Callable[[int], str] | None = None,
upper_bound: int | None = None,
*,
_eager: bool = False,
upper_bound: int = 0,
) -> Expr:
"""
Convert the Series of type `List` to a Series of type `Struct`.
Expand Down Expand Up @@ -1134,13 +1132,6 @@ def to_struct(
lengths then `n_field_strategy="max_width"` must be used to obtain the expected
result.
Warnings
--------
If `fields` is not provided, or if `fields` is a function and
`upper_bound` is not set, this may lead to unexpected results.
Future versions of Polars may be changed to raise an error when
these are unspecified.
Examples
--------
Convert list to struct with default field name assignment:
Expand Down Expand Up @@ -1194,28 +1185,6 @@ def to_struct(
pyexpr = self._pyexpr.list_to_struct_fixed_width(fields)
return wrap_expr(pyexpr)
else:
if not _eager:
otherwise = (
"otherwise the output schema will not be known, "
"causing subsequent operations to fail. "
"Future versions of Polars may be changed "
"to raise an error when this is unspecified."
)

if fields is None:
warnings.warn(
f"`fields` should be specified when calling list.to_struct, {otherwise}",
DeprecationWarning,
stacklevel=find_stacklevel(),
)
elif callable(fields) and upper_bound is None: # type: ignore[redundant-expr]
warnings.warn(
f"`upper_bound` should be specified when calling list.to_struct with a function as `fields`, {otherwise}",
DeprecationWarning,
stacklevel=find_stacklevel(),
)

upper_bound = upper_bound or 0
pyexpr = self._pyexpr.list_to_struct(n_field_strategy, fields, upper_bound)
return wrap_expr(pyexpr)

Expand Down
1 change: 0 additions & 1 deletion py-polars/polars/series/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,6 @@ def to_struct(
n_field_strategy,
fields,
upper_bound=0,
_eager=True,
)
)
.to_series()
Expand Down
18 changes: 0 additions & 18 deletions py-polars/tests/unit/operations/namespaces/list/test_list.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import re
import warnings
from datetime import date, datetime

import numpy as np
Expand Down Expand Up @@ -629,23 +628,6 @@ def test_list_unique2() -> None:
def test_list_to_struct() -> None:
df = pl.DataFrame({"n": [[0, 1, 2], [0, 1]]})

# Test the warnings before we go into ignore
with pytest.raises(DeprecationWarning, match="`fields` should be specified"):
df.select(pl.first().list.to_struct())

with pytest.raises(DeprecationWarning, match="`upper_bound` should be specified"):
df.select(pl.first().list.to_struct(fields=str))

df.select(pl.first().list.to_struct(fields=["a"]))
df.select(pl.first().list.to_struct(fields=str, upper_bound=1))

# Calling on Series should not trigger the warnings
s = df.to_series()
s.list.to_struct()
s.list.to_struct(fields=str)

warnings.filterwarnings("ignore", category=DeprecationWarning)

assert df.select(pl.col("n").list.to_struct()).rows(named=True) == [
{"n": {"field_0": 0, "field_1": 1, "field_2": 2}},
{"n": {"field_0": 0, "field_1": 1, "field_2": None}},
Expand Down

0 comments on commit c9197aa

Please sign in to comment.