Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

depr(python): Deprecate default value for radix in parse_int #11615

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions py-polars/polars/expr/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from polars.utils._wrap import wrap_expr
from polars.utils.deprecation import (
deprecate_renamed_function,
issue_deprecation_warning,
rename_use_earliest_to_ambiguous,
)
from polars.utils.various import find_stacklevel
Expand Down Expand Up @@ -1917,18 +1918,16 @@ def explode(self) -> Expr:
"""
return wrap_expr(self._pyexpr.str_explode())

def parse_int(self, radix: int = 2, *, strict: bool = True) -> Expr:
def parse_int(self, radix: int | None = None, *, strict: bool = True) -> Expr:
"""
Parse integers with base radix from strings.

By default base 2. ParseError/Overflows become Nulls.
ParseError/Overflows become Nulls.

Parameters
----------
radix
Positive integer which is the base of the string we are parsing.
Default: 2.

strict
Bool, Default=True will raise any ParseError or overflow as ComputeError.
False silently convert to Null.
Expand Down Expand Up @@ -1969,6 +1968,14 @@ def parse_int(self, radix: int = 2, *, strict: bool = True) -> Expr:
└───────┘

"""
if radix is None:
issue_deprecation_warning(
"The default value for the `radix` parameter of `parse_int` will be removed in a future version."
" Call `parse_int(radix=2)` to keep current behavior and silence this warning.",
version="0.19.8",
)
radix = 2

return wrap_expr(self._pyexpr.str_parse_int(radix, strict))

@deprecate_renamed_function("strip_chars", version="0.19.3")
Expand Down
8 changes: 3 additions & 5 deletions py-polars/polars/series/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,18 +1457,16 @@ def explode(self) -> Series:

"""

def parse_int(self, radix: int = 2, *, strict: bool = True) -> Series:
r"""
def parse_int(self, radix: int | None = None, *, strict: bool = True) -> Series:
"""
Parse integers with base radix from strings.

By default base 2. ParseError/Overflows become Nulls.
ParseError/Overflows become Nulls.

Parameters
----------
radix
Positive integer which is the base of the string we are parsing.
Default: 2

strict
Bool, Default=True will raise any ParseError or overflow as ComputeError.
False silently convert to Null.
Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/unit/namespaces/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ def test_str_parse_int_df() -> None:
)


def test_str_parse_int_deprecated_default() -> None:
s = pl.Series(["110", "101", "010"])
with pytest.deprecated_call(match="default value"):
result = s.str.parse_int()
expected = pl.Series([6, 5, 2], dtype=pl.Int32)
assert_series_equal(result, expected)


def test_str_strip_chars_expr() -> None:
df = pl.DataFrame(
{
Expand Down