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

docs(python): Clarify docstrings for closed argument #6198

Merged
merged 2 commits into from
Jan 13, 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
12 changes: 6 additions & 6 deletions py-polars/polars/internals/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
from polars.internals.type_aliases import (
AsofJoinStrategy,
AvroCompression,
ClosedWindow,
ClosedInterval,
ComparisonOperator,
CsvEncoding,
FillNullStrategy,
Expand Down Expand Up @@ -3347,7 +3347,7 @@ def groupby_rolling(
*,
period: str | timedelta,
offset: str | timedelta | None = None,
closed: ClosedWindow = "right",
closed: ClosedInterval = "right",
by: str | Sequence[str] | pli.Expr | Sequence[pli.Expr] | None = None,
) -> RollingGroupBy[DF]:
"""
Expand Down Expand Up @@ -3398,7 +3398,7 @@ def groupby_rolling(
offset
offset of the window. Default is -period
closed : {'right', 'left', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).
by
Also group by this column/these columns

Expand Down Expand Up @@ -3456,7 +3456,7 @@ def groupby_dynamic(
offset: str | timedelta | None = None,
truncate: bool = True,
include_boundaries: bool = False,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
by: str | Sequence[str] | pli.Expr | Sequence[pli.Expr] | None = None,
start_by: StartBy = "window",
) -> DynamicGroupBy[DF]:
Expand Down Expand Up @@ -3521,8 +3521,8 @@ def groupby_dynamic(
Add the lower and upper bound of the window to the "_lower_bound" and
"_upper_bound" columns. This will impact performance because it's harder to
parallelize
closed : {'right', 'left', 'both', 'none'}
Define whether the temporal window interval is closed or not.
closed : {'left', 'right', 'both', 'none'}
Define which sides of the temporal interval are closed (inclusive).
by
Also group by this column/these columns
start_by : {'window', 'datapoint', 'monday'}
Expand Down
6 changes: 3 additions & 3 deletions py-polars/polars/internals/dataframe/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

if TYPE_CHECKING:
from polars.internals.type_aliases import (
ClosedWindow,
ClosedInterval,
RollingInterpolationMethod,
StartBy,
)
Expand Down Expand Up @@ -736,7 +736,7 @@ def __init__(
index_column: str,
period: str | timedelta,
offset: str | timedelta | None,
closed: ClosedWindow = "none",
closed: ClosedInterval = "none",
by: str | Sequence[str] | pli.Expr | Sequence[pli.Expr] | None = None,
):
period = _timedelta_to_pl_duration(period)
Expand Down Expand Up @@ -781,7 +781,7 @@ def __init__(
offset: str | timedelta | None,
truncate: bool = True,
include_boundaries: bool = True,
closed: ClosedWindow = "none",
closed: ClosedInterval = "none",
by: str | Sequence[str] | pli.Expr | Sequence[pli.Expr] | None = None,
start_by: StartBy = "window",
):
Expand Down
38 changes: 19 additions & 19 deletions py-polars/polars/internals/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

if TYPE_CHECKING:
from polars.internals.type_aliases import (
ClosedWindow,
ClosedInterval,
FillNullStrategy,
InterpolationMethod,
NullBehavior,
Expand Down Expand Up @@ -3412,7 +3412,7 @@ def is_between(
start: Expr | datetime | date | int | float,
end: Expr | datetime | date | int | float,
include_bounds: bool | tuple[bool, bool] | None = None,
closed: ClosedWindow | None = None,
closed: ClosedInterval | None = None,
) -> Expr:
"""
Check if this expression is between start and end.
Expand All @@ -3433,7 +3433,7 @@ def is_between(
- (False, True): Exclude start and include end.
- (True, False): Include start and exclude end.
closed : {'none', 'left', 'right', 'both'}
Define whether the interval is closed or not. Defaults to 'none'.
Define which sides of the interval are closed (inclusive).

Returns
-------
Expand Down Expand Up @@ -3708,7 +3708,7 @@ def rolling_min(
min_periods: int | None = None,
center: bool = False,
by: str | None = None,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
) -> Expr:
"""
Apply a rolling min (moving min) over the values in this array.
Expand Down Expand Up @@ -3750,7 +3750,7 @@ def rolling_min(
set the column that will be used to determine the windows. This column must
be of dtype `{Date, Datetime}`
closed : {'left', 'right', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).

Warnings
--------
Expand Down Expand Up @@ -3804,7 +3804,7 @@ def rolling_max(
min_periods: int | None = None,
center: bool = False,
by: str | None = None,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
) -> Expr:
"""
Apply a rolling max (moving max) over the values in this array.
Expand Down Expand Up @@ -3846,7 +3846,7 @@ def rolling_max(
set the column that will be used to determine the windows. This column must
be of dtype `{Date, Datetime}`
closed : {'left', 'right', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).

Warnings
--------
Expand Down Expand Up @@ -3900,7 +3900,7 @@ def rolling_mean(
min_periods: int | None = None,
center: bool = False,
by: str | None = None,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
) -> Expr:
"""
Apply a rolling mean (moving mean) over the values in this array.
Expand Down Expand Up @@ -3942,7 +3942,7 @@ def rolling_mean(
set the column that will be used to determine the windows. This column must
be of dtype `{Date, Datetime}`
closed : {'left', 'right', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).

Warnings
--------
Expand Down Expand Up @@ -3994,7 +3994,7 @@ def rolling_sum(
min_periods: int | None = None,
center: bool = False,
by: str | None = None,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
) -> Expr:
"""
Apply a rolling sum (moving sum) over the values in this array.
Expand Down Expand Up @@ -4036,7 +4036,7 @@ def rolling_sum(
set the column that will be used to determine the windows. This column must
of dtype `{Date, Datetime}`
closed : {'left', 'right', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).

Warnings
--------
Expand Down Expand Up @@ -4090,7 +4090,7 @@ def rolling_std(
min_periods: int | None = None,
center: bool = False,
by: str | None = None,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
) -> Expr:
"""
Compute a rolling standard deviation.
Expand Down Expand Up @@ -4132,7 +4132,7 @@ def rolling_std(
set the column that will be used to determine the windows. This column must
be of dtype `{Date, Datetime}`
closed : {'left', 'right', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).

Warnings
--------
Expand Down Expand Up @@ -4186,7 +4186,7 @@ def rolling_var(
min_periods: int | None = None,
center: bool = False,
by: str | None = None,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
) -> Expr:
"""
Compute a rolling variance.
Expand Down Expand Up @@ -4228,7 +4228,7 @@ def rolling_var(
set the column that will be used to determine the windows. This column must
be of dtype `{Date, Datetime}`
closed : {'left', 'right', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).

Warnings
--------
Expand Down Expand Up @@ -4282,7 +4282,7 @@ def rolling_median(
min_periods: int | None = None,
center: bool = False,
by: str | None = None,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
) -> Expr:
"""
Compute a rolling median.
Expand Down Expand Up @@ -4320,7 +4320,7 @@ def rolling_median(
set the column that will be used to determine the windows. This column must
be of dtype `{Date, Datetime}`
closed : {'left', 'right', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).

Warnings
--------
Expand Down Expand Up @@ -4376,7 +4376,7 @@ def rolling_quantile(
min_periods: int | None = None,
center: bool = False,
by: str | None = None,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
) -> Expr:
"""
Compute a rolling quantile.
Expand Down Expand Up @@ -4418,7 +4418,7 @@ def rolling_quantile(
set the column that will be used to determine the windows. This column must
be of dtype `{Date, Datetime}`
closed : {'left', 'right', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).

Warnings
--------
Expand Down
12 changes: 6 additions & 6 deletions py-polars/polars/internals/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
_DOCUMENTING = True

if TYPE_CHECKING:
from polars.internals.type_aliases import ClosedWindow, ConcatMethod, TimeUnit
from polars.internals.type_aliases import ClosedInterval, ConcatMethod, TimeUnit


def get_dummies(
Expand Down Expand Up @@ -277,7 +277,7 @@ def date_range(
interval: str | timedelta,
*,
lazy: Literal[False] = ...,
closed: ClosedWindow = "both",
closed: ClosedInterval = "both",
name: str | None = None,
time_unit: TimeUnit | None = None,
time_zone: str | None = None,
Expand All @@ -292,7 +292,7 @@ def date_range(
interval: str | timedelta,
*,
lazy: Literal[False] = ...,
closed: ClosedWindow = "both",
closed: ClosedInterval = "both",
name: str | None = None,
time_unit: TimeUnit | None = None,
time_zone: str | None = None,
Expand All @@ -307,7 +307,7 @@ def date_range(
interval: str | timedelta,
*,
lazy: Literal[False] = ...,
closed: ClosedWindow = "both",
closed: ClosedInterval = "both",
name: str | None = None,
time_unit: TimeUnit | None = None,
time_zone: str | None = None,
Expand All @@ -322,7 +322,7 @@ def date_range(
interval: str | timedelta,
*,
lazy: Literal[True],
closed: ClosedWindow = "both",
closed: ClosedInterval = "both",
name: str | None = None,
time_unit: TimeUnit | None = None,
time_zone: str | None = None,
Expand All @@ -337,7 +337,7 @@ def date_range(
interval: str | timedelta,
*,
lazy: bool = False,
closed: ClosedWindow = "both",
closed: ClosedInterval = "both",
name: str | None = None,
time_unit: TimeUnit | None = None,
time_zone: str | None = None,
Expand Down
10 changes: 5 additions & 5 deletions py-polars/polars/internals/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
if TYPE_CHECKING:
from polars.internals.type_aliases import (
AsofJoinStrategy,
ClosedWindow,
ClosedInterval,
CsvEncoding,
FillNullStrategy,
JoinStrategy,
Expand Down Expand Up @@ -1646,7 +1646,7 @@ def groupby_rolling(
*,
period: str | timedelta,
offset: str | timedelta | None = None,
closed: ClosedWindow = "right",
closed: ClosedInterval = "right",
by: str | Sequence[str] | pli.Expr | Sequence[pli.Expr] | None = None,
) -> LazyGroupBy[LDF]:
"""
Expand Down Expand Up @@ -1697,7 +1697,7 @@ def groupby_rolling(
offset
offset of the window. Default is -period
closed : {'right', 'left', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).
by
Also group by this column/these columns

Expand Down Expand Up @@ -1765,7 +1765,7 @@ def groupby_dynamic(
offset: str | timedelta | None = None,
truncate: bool = True,
include_boundaries: bool = False,
closed: ClosedWindow = "left",
closed: ClosedInterval = "left",
by: str | Sequence[str] | pli.Expr | Sequence[pli.Expr] | None = None,
start_by: StartBy = "window",
) -> LazyGroupBy[LDF]:
Expand Down Expand Up @@ -1831,7 +1831,7 @@ def groupby_dynamic(
"_upper_bound" columns. This will impact performance because it's harder to
parallelize
closed : {'right', 'left', 'both', 'none'}
Define whether the temporal window interval is closed or not.
Define which sides of the temporal interval are closed (inclusive).
by
Also group by this column/these columns
start_by : {'window', 'datapoint', 'monday'}
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# The following all have an equivalent Rust enum with the same name
AvroCompression: TypeAlias = Literal["uncompressed", "snappy", "deflate"]
CategoricalOrdering: TypeAlias = Literal["physical", "lexical"]
ClosedWindow: TypeAlias = Literal["left", "right", "both", "none"]
StartBy: TypeAlias = Literal["window", "datapoint", "monday"]
CsvEncoding: TypeAlias = Literal["utf8", "utf8-lossy"]
FillNullStrategy: TypeAlias = Literal[
Expand Down Expand Up @@ -56,6 +55,7 @@

# The following have a Rust enum equivalent with a different name
AsofJoinStrategy: TypeAlias = Literal["backward", "forward"] # AsofStrategy
ClosedInterval: TypeAlias = Literal["left", "right", "both", "none"] # ClosedWindow
RollingInterpolationMethod: TypeAlias = Literal[
"nearest", "higher", "lower", "midpoint", "linear"
] # QuantileInterpolOptions
Expand Down
5 changes: 2 additions & 3 deletions py-polars/tests/unit/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from polars.testing import assert_frame_equal

if TYPE_CHECKING:
from polars.internals.type_aliases import ClosedWindow
from polars.internals.type_aliases import ClosedInterval


def test_rolling_kernels_and_groupby_rolling() -> None:
Expand All @@ -35,9 +35,8 @@ def test_rolling_kernels_and_groupby_rolling() -> None:
timedelta(days=2),
timedelta(days=3),
]:
closed_windows: list[ClosedWindow] = ["left", "right", "none", "both"]
closed_windows: list[ClosedInterval] = ["left", "right", "none", "both"]
for closed in closed_windows:

out1 = df.select(
[
pl.col("dt"),
Expand Down