Skip to content

Commit

Permalink
refactor[python]: Dispatch more Series methods to Expr (#4586)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Aug 27, 2022
1 parent 0f08272 commit d718f6a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 161 deletions.
4 changes: 2 additions & 2 deletions py-polars/polars/internals/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3495,7 +3495,7 @@ def hash(
k3 = seed_3 if seed_3 is not None else seed
return wrap_expr(self._pyexpr.hash(k0, k1, k2, k3))

def reinterpret(self, signed: bool) -> Expr:
def reinterpret(self, signed: bool = True) -> Expr:
"""
Reinterpret the underlying bits as a signed/unsigned integer.
Expand Down Expand Up @@ -4658,7 +4658,7 @@ def diff(self, n: int = 1, null_behavior: NullBehavior = "ignore") -> Expr:
Parameters
----------
n
number of slots to shift
Number of slots to shift.
null_behavior : {'ignore', 'drop'}
How to handle null values.
Expand Down
2 changes: 0 additions & 2 deletions py-polars/polars/internals/series/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def concat(self, other: list[pli.Series] | pli.Series | list[Any]) -> pli.Series
Columns to concat into a List Series
"""
s = pli.wrap_s(self._s)
return s.to_frame().select(pli.col(s.name).arr.concat(other)).to_series()

def get(self, index: int) -> pli.Series:
"""
Expand Down
33 changes: 0 additions & 33 deletions py-polars/polars/internals/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,6 @@ def is_null(self) -> Series:
]
"""
return wrap_s(self._s.is_null())

def is_not_null(self) -> Series:
"""
Expand All @@ -1781,7 +1780,6 @@ def is_not_null(self) -> Series:
]
"""
return wrap_s(self._s.is_not_null())

def is_finite(self) -> Series:
"""
Expand All @@ -1805,7 +1803,6 @@ def is_finite(self) -> Series:
]
"""
return wrap_s(self._s.is_finite())

def is_infinite(self) -> Series:
"""
Expand All @@ -1829,7 +1826,6 @@ def is_infinite(self) -> Series:
]
"""
return wrap_s(self._s.is_infinite())

def is_nan(self) -> Series:
"""
Expand All @@ -1854,7 +1850,6 @@ def is_nan(self) -> Series:
]
"""
return wrap_s(self._s.is_nan())

def is_not_nan(self) -> Series:
"""
Expand All @@ -1879,7 +1874,6 @@ def is_not_nan(self) -> Series:
]
"""
return wrap_s(self._s.is_not_nan())

def is_in(self, other: Series | Sequence[Any]) -> Series:
"""
Expand Down Expand Up @@ -1931,7 +1925,6 @@ def is_in(self, other: Series | Sequence[Any]) -> Series:
]
"""
return self.to_frame().select(pli.col(self.name).is_in(other)).to_series()

def arg_true(self) -> Series:
"""
Expand Down Expand Up @@ -1966,7 +1959,6 @@ def is_unique(self) -> Series:
]
"""
return wrap_s(self._s.is_unique())

def is_first(self) -> Series:
"""
Expand All @@ -1977,7 +1969,6 @@ def is_first(self) -> Series:
Boolean Series
"""
return wrap_s(self._s.is_first())

def is_duplicated(self) -> Series:
"""
Expand All @@ -2001,7 +1992,6 @@ def is_duplicated(self) -> Series:
]
"""
return wrap_s(self._s.is_duplicated())

def explode(self) -> Series:
"""
Expand Down Expand Up @@ -2029,7 +2019,6 @@ def explode(self) -> Series:
Exploded Series of same dtype
"""
return wrap_s(self._s.explode())

def series_equal(
self, other: Series, null_equal: bool = False, strict: bool = False
Expand Down Expand Up @@ -2119,8 +2108,6 @@ def cast(
]
"""
pl_dtype = py_type_to_dtype(dtype)
return wrap_s(self._s.cast(pl_dtype, strict))

def to_physical(self) -> Series:
"""
Expand Down Expand Up @@ -2152,7 +2139,6 @@ def to_physical(self) -> Series:
]
"""
return wrap_s(self._s.to_physical())

def to_list(self, use_pyarrow: bool = False) -> list[Any | None]:
"""
Expand Down Expand Up @@ -2224,7 +2210,6 @@ def reverse(self) -> Series:
]
"""
return wrap_s(self._s.reverse())

def is_numeric(self) -> bool:
"""
Expand Down Expand Up @@ -2699,7 +2684,6 @@ def floor(self) -> Series:
Only works on floating point Series
"""
return wrap_s(self._s.floor())

def ceil(self) -> Series:
"""
Expand Down Expand Up @@ -2732,7 +2716,6 @@ def round(self, decimals: int) -> Series:
number of decimals to round by.
"""
return wrap_s(self._s.round(decimals))

def dot(self, other: Series) -> float | None:
"""
Expand Down Expand Up @@ -2768,7 +2751,6 @@ def mode(self) -> Series:
]
"""
return wrap_s(self._s.mode())

def sign(self) -> Series:
"""
Expand Down Expand Up @@ -3085,7 +3067,6 @@ def shift(self, periods: int = 1) -> Series:
Number of places to shift (may be negative).
"""
return wrap_s(self._s.shift(periods))

def shift_and_fill(self, periods: int, fill_value: int | pli.Expr) -> Series:
"""
Expand Down Expand Up @@ -3734,11 +3715,6 @@ def hash(
]
"""
k0 = seed
k1 = seed_1 if seed_1 is not None else seed
k2 = seed_2 if seed_2 is not None else seed
k3 = seed_3 if seed_3 is not None else seed
return wrap_s(self._s.hash(k0, k1, k2, k3))

def reinterpret(self, signed: bool = True) -> Series:
"""
Expand All @@ -3753,7 +3729,6 @@ def reinterpret(self, signed: bool = True) -> Series:
If True, reinterpret as `pl.Int64`. Otherwise, reinterpret as `pl.UInt64`.
"""
return wrap_s(self._s.reinterpret(signed))

def interpolate(self) -> Series:
"""
Expand All @@ -3774,11 +3749,9 @@ def interpolate(self) -> Series:
]
"""
return wrap_s(self._s.interpolate())

def abs(self) -> Series:
"""Compute absolute values."""
return wrap_s(self._s.abs())

def rank(self, method: RankMethod = "average", reverse: bool = False) -> Series:
"""
Expand Down Expand Up @@ -3838,7 +3811,6 @@ def rank(self, method: RankMethod = "average", reverse: bool = False) -> Series:
]
"""
return wrap_s(self._s.rank(method, reverse))

def diff(self, n: int = 1, null_behavior: NullBehavior = "ignore") -> Series:
"""
Expand All @@ -3852,7 +3824,6 @@ def diff(self, n: int = 1, null_behavior: NullBehavior = "ignore") -> Series:
How to handle null values.
"""
return wrap_s(self._s.diff(n, null_behavior))

def pct_change(self, n: int = 1) -> Series:
"""
Expand Down Expand Up @@ -4010,7 +3981,6 @@ def clip_min(self, min_val: int | float) -> Series:
Minimum value.
"""
return self.to_frame().select(pli.col(self.name).clip_min(min_val))[self.name]

def clip_max(self, max_val: int | float) -> Series:
"""
Expand All @@ -4027,7 +3997,6 @@ def clip_max(self, max_val: int | float) -> Series:
Maximum value.
"""
return self.to_frame().select(pli.col(self.name).clip_max(max_val))[self.name]

def reshape(self, dims: tuple[int, ...]) -> Series:
"""
Expand All @@ -4046,7 +4015,6 @@ def reshape(self, dims: tuple[int, ...]) -> Series:
Series
"""
return wrap_s(self._s.reshape(dims))

def shuffle(self, seed: int | None = None) -> Series:
"""
Expand Down Expand Up @@ -4245,7 +4213,6 @@ def extend_constant(self, value: int | float | str | bool | None, n: int) -> Ser
]
"""
return wrap_s(self._s.extend_constant(value, n))

def set_sorted(self, reverse: bool = False) -> Series:
"""
Expand Down

0 comments on commit d718f6a

Please sign in to comment.