Skip to content

Commit

Permalink
fix(python): ensure multi-line type hints are parenthesised (#6100)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jan 7, 2023
1 parent 4a55e0d commit d991fb8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 57 deletions.
31 changes: 16 additions & 15 deletions py-polars/polars/internals/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,11 +1211,13 @@ def __getitem__(self: DF, item: str) -> pli.Series:
@overload
def __getitem__(
self: DF,
item: int
| np.ndarray[Any, Any]
| MultiColSelector
| tuple[int, MultiColSelector]
| tuple[MultiRowSelector, MultiColSelector],
item: (
int
| np.ndarray[Any, Any]
| MultiColSelector
| tuple[int, MultiColSelector]
| tuple[MultiRowSelector, MultiColSelector]
),
) -> DF:
...

Expand Down Expand Up @@ -2493,12 +2495,9 @@ def insert_at_idx(self: DF, index: int, series: pli.Series) -> DF:

def filter(
self,
predicate: pli.Expr
| str
| pli.Series
| list[bool]
| np.ndarray[Any, Any]
| bool,
predicate: (
pli.Expr | str | pli.Series | list[bool] | np.ndarray[Any, Any] | bool
),
) -> DataFrame:
"""
Filter the rows in the DataFrame based on a predicate expression.
Expand Down Expand Up @@ -5360,10 +5359,12 @@ def lazy(self: DF) -> pli.LazyFrame:

def select(
self: DF,
exprs: str
| pli.Expr
| pli.Series
| Iterable[str | pli.Expr | pli.Series | pli.WhenThen | pli.WhenThenThen],
exprs: (
str
| pli.Expr
| pli.Series
| Iterable[str | pli.Expr | pli.Series | pli.WhenThen | pli.WhenThenThen]
),
) -> DF:
"""
Select columns from this DataFrame.
Expand Down
26 changes: 14 additions & 12 deletions py-polars/polars/internals/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,23 @@


def selection_to_pyexpr_list(
exprs: str
| Expr
| pli.Series
| Iterable[
exprs: (
str
| Expr
| pli.Series
| timedelta
| date
| datetime
| int
| float
| pli.WhenThen
| pli.WhenThenThen
],
| Iterable[
str
| Expr
| pli.Series
| timedelta
| date
| datetime
| int
| float
| pli.WhenThen
| pli.WhenThenThen
]
),
) -> list[PyExpr]:
if isinstance(exprs, (str, Expr, pli.Series)):
exprs = [exprs]
Expand Down
22 changes: 13 additions & 9 deletions py-polars/polars/internals/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,11 +831,13 @@ def inspect(s: pli.DataFrame) -> pli.DataFrame:

def sort(
self: LDF,
by: str
| pli.Expr
| Sequence[str]
| Sequence[pli.Expr]
| Sequence[str | pli.Expr],
by: (
str
| pli.Expr
| Sequence[str]
| Sequence[pli.Expr]
| Sequence[str | pli.Expr]
),
reverse: bool | Sequence[bool] = False,
nulls_last: bool = False,
) -> LDF:
Expand Down Expand Up @@ -1504,10 +1506,12 @@ def filter(self: LDF, predicate: pli.Expr | str | pli.Series | list[bool]) -> LD

def select(
self: LDF,
exprs: str
| pli.Expr
| pli.Series
| Iterable[str | pli.Expr | pli.Series | pli.WhenThen | pli.WhenThenThen],
exprs: (
str
| pli.Expr
| pli.Series
| Iterable[str | pli.Expr | pli.Series | pli.WhenThen | pli.WhenThenThen]
),
) -> LDF:
"""
Select columns from this DataFrame.
Expand Down
40 changes: 19 additions & 21 deletions py-polars/polars/internals/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,13 +753,9 @@ def __getitem__(

def __getitem__(
self,
item: int
| Series
| range
| slice
| np.ndarray[Any, Any]
| list[int]
| list[bool],
item: (
int | Series | range | slice | np.ndarray[Any, Any] | list[int] | list[bool]
),
) -> Any:

if isinstance(item, Series) and item.dtype in {
Expand Down Expand Up @@ -2920,20 +2916,22 @@ def set(self, filter: Series, value: int | float | str) -> Series:
def set_at_idx(
self,
idx: Series | np.ndarray[Any, Any] | Sequence[int] | int,
value: int
| float
| str
| bool
| Sequence[int]
| Sequence[float]
| Sequence[bool]
| Sequence[str]
| Sequence[date]
| Sequence[datetime]
| date
| datetime
| Series
| None,
value: (
int
| float
| str
| bool
| Sequence[int]
| Sequence[float]
| Sequence[bool]
| Sequence[str]
| Sequence[date]
| Sequence[datetime]
| date
| datetime
| Series
| None
),
) -> Series:
"""
Set values at the index locations.
Expand Down

0 comments on commit d991fb8

Please sign in to comment.