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): Rename first qcut parameter to quantiles #10253

Merged
merged 1 commit into from
Aug 2, 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
16 changes: 10 additions & 6 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3363,10 +3363,11 @@ def cut(
self._pyexpr.cut(breaks, labels, left_closed, include_breaks)
)

@deprecate_renamed_parameter("probs", "q", version="0.18.8")
@deprecate_renamed_parameter("probs", "quantiles", version="0.18.8")
@deprecate_renamed_parameter("q", "quantiles", version="0.18.12")
def qcut(
self,
q: list[float] | int,
quantiles: list[float] | int,
labels: list[str] | None = None,
left_closed: bool = False,
allow_duplicates: bool = False,
Expand All @@ -3377,7 +3378,7 @@ def qcut(

Parameters
----------
q
quantiles
Either a list of quantile probabilities between 0 and 1 or a positive
integer determining the number of evenly spaced probabilities to use.
labels
Expand All @@ -3393,7 +3394,6 @@ def qcut(
Include the the right endpoint of the bin each observation falls in.
If True, the resulting column will be a Struct.


Examples
--------
>>> g = pl.repeat("a", 5, eager=True).append(pl.repeat("b", 5, eager=True))
Expand Down Expand Up @@ -3484,9 +3484,13 @@ def qcut(
│ b ┆ 9 ┆ {inf,"(4.5, inf]"} │
└─────┴─────┴───────────────────────┘
"""
expr_f = self._pyexpr.qcut_uniform if isinstance(q, int) else self._pyexpr.qcut
expr_f = (
self._pyexpr.qcut_uniform
if isinstance(quantiles, int)
else self._pyexpr.qcut
)
return self._from_pyexpr(
expr_f(q, labels, left_closed, allow_duplicates, include_breaks)
expr_f(quantiles, labels, left_closed, allow_duplicates, include_breaks)
)

def rle(self) -> Self:
Expand Down
12 changes: 7 additions & 5 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1740,10 +1740,10 @@ def cut(
return res.struct.rename_fields([break_point_label, category_label])
return res

@deprecate_renamed_parameter("quantiles", "q", version="0.18.8")
@deprecate_renamed_parameter("q", "quantiles", version="0.18.12")
def qcut(
self,
q: list[float] | int,
quantiles: list[float] | int,
*,
labels: list[str] | None = None,
break_point_label: str = "break_point",
Expand All @@ -1758,7 +1758,7 @@ def qcut(

Parameters
----------
q
quantiles
Either a list of quantile probabilities between 0 and 1 or a positive
integer determining the number of evenly spaced probabilities to use.
labels
Expand Down Expand Up @@ -1857,7 +1857,7 @@ def qcut(
self.to_frame()
.with_columns(
F.col(n)
.qcut(q, labels, left_closed, allow_duplicates, True)
.qcut(quantiles, labels, left_closed, allow_duplicates, True)
.alias(n + "_bin")
)
.unnest(n + "_bin")
Expand All @@ -1866,7 +1866,9 @@ def qcut(
res = (
self.to_frame()
.select(
F.col(n).qcut(q, labels, left_closed, allow_duplicates, include_breaks)
F.col(n).qcut(
quantiles, labels, left_closed, allow_duplicates, include_breaks
)
)
.to_series()
)
Expand Down