Skip to content

Commit

Permalink
refactor[python]: Dispatch more Series methods to Expr (#4593)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Aug 28, 2022
1 parent 828944d commit b79dc8d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 53 deletions.
3 changes: 2 additions & 1 deletion py-polars/polars/internals/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2839,7 +2839,8 @@ def quantile(
def filter(self, predicate: Expr) -> Expr:
"""
Filter a single column.
Mostly useful in in aggregation context. If you want to filter on a DataFrame
Mostly useful in an aggregation context. If you want to filter on a DataFrame
level, use `LazyFrame.filter`.
Parameters
Expand Down
17 changes: 0 additions & 17 deletions py-polars/polars/internals/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ def sqrt(self) -> Series:
]
"""
return self**0.5

def any(self) -> bool:
"""
Expand Down Expand Up @@ -722,18 +721,15 @@ def log(self, base: float = math.e) -> Series:

def log10(self) -> Series:
"""Compute the base 10 logarithm of the input array, element-wise."""
return self.log(10.0)

def exp(self) -> Series:
"""Compute the exponential, element-wise."""

def drop_nulls(self) -> Series:
"""Create a new Series that copies data from this Series without null values."""
return wrap_s(self._s.drop_nulls())

def drop_nans(self) -> Series:
"""Drop NaN values."""
return self.filter(self.is_not_nan())

def to_frame(self) -> pli.DataFrame:
"""
Expand Down Expand Up @@ -1097,7 +1093,6 @@ def unique_counts(self) -> Series:
]
"""
return pli.select(pli.lit(self).unique_counts()).to_series()

def entropy(self, base: float = math.e, normalize: bool = False) -> float | None:
"""
Expand Down Expand Up @@ -1165,9 +1160,6 @@ def cumulative_eval(
]
"""
return pli.select(
pli.lit(self).cumulative_eval(expr, min_periods, parallel)
).to_series()

@property
def name(self) -> str:
Expand Down Expand Up @@ -1270,7 +1262,6 @@ def cumsum(self, reverse: bool = False) -> Series:
]
"""
return wrap_s(self._s.cumsum(reverse))

def cummin(self, reverse: bool = False) -> Series:
"""
Expand All @@ -1294,7 +1285,6 @@ def cummin(self, reverse: bool = False) -> Series:
]
"""
return wrap_s(self._s.cummin(reverse))

def cummax(self, reverse: bool = False) -> Series:
"""
Expand All @@ -1318,7 +1308,6 @@ def cummax(self, reverse: bool = False) -> Series:
]
"""
return wrap_s(self._s.cummax(reverse))

def cumprod(self, reverse: bool = False) -> Series:
"""
Expand Down Expand Up @@ -1347,7 +1336,6 @@ def cumprod(self, reverse: bool = False) -> Series:
]
"""
return wrap_s(self._s.cumprod(reverse))

def limit(self, num_elements: int = 10) -> Series:
"""
Expand Down Expand Up @@ -1549,7 +1537,6 @@ def take_every(self, n: int) -> Series:
]
"""
return wrap_s(self._s.take_every(n))

@overload
def sort(self, reverse: bool = False, *, in_place: Literal[False] = ...) -> Series:
Expand Down Expand Up @@ -1633,7 +1620,6 @@ def argsort(self, reverse: bool = False, nulls_last: bool = False) -> Series:

def arg_unique(self) -> Series:
"""Get unique index as Series."""
return wrap_s(self._s.arg_unique())

def arg_min(self) -> int | None:
"""Get the index of the minimal value."""
Expand Down Expand Up @@ -1679,9 +1665,6 @@ def unique(self, maintain_order: bool = False) -> Series:
]
"""
if maintain_order:
return pli.select(pli.lit(self).unique(maintain_order)).to_series()
return wrap_s(self._s.unique())

def take(
self, indices: int | list[int] | pli.Expr | Series | np.ndarray[Any, Any]
Expand Down
35 changes: 0 additions & 35 deletions py-polars/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,22 +421,6 @@ impl PySeries {
Ok(out.into())
}

pub fn cumsum(&self, reverse: bool) -> Self {
self.series.cumsum(reverse).into()
}

pub fn cummax(&self, reverse: bool) -> Self {
self.series.cummax(reverse).into()
}

pub fn cummin(&self, reverse: bool) -> Self {
self.series.cummin(reverse).into()
}

pub fn cumprod(&self, reverse: bool) -> Self {
self.series.cumprod(reverse).into()
}

pub fn chunk_lengths(&self) -> Vec<usize> {
self.series.chunk_lengths().collect()
}
Expand Down Expand Up @@ -566,11 +550,6 @@ impl PySeries {
.into()
}

pub fn unique(&self) -> PyResult<Self> {
let unique = self.series.unique().map_err(PyPolarsErr::from)?;
Ok(unique.into())
}

pub fn value_counts(&self, sorted: bool) -> PyResult<PyDataFrame> {
let df = self
.series
Expand All @@ -579,11 +558,6 @@ impl PySeries {
Ok(df.into())
}

pub fn arg_unique(&self) -> PyResult<Self> {
let arg_unique = self.series.arg_unique().map_err(PyPolarsErr::from)?;
Ok(arg_unique.into_series().into())
}

pub fn arg_min(&self) -> Option<usize> {
self.series.arg_min()
}
Expand Down Expand Up @@ -634,11 +608,6 @@ impl PySeries {
Ok(s.into())
}

pub fn take_every(&self, n: usize) -> Self {
let s = self.series.take_every(n);
s.into()
}

pub fn series_equal(&self, other: &PySeries, null_equal: bool, strict: bool) -> bool {
if strict {
self.series.eq(&other.series)
Expand Down Expand Up @@ -809,10 +778,6 @@ impl PySeries {
Ok(ptr)
}

pub fn drop_nulls(&self) -> Self {
self.series.drop_nulls().into()
}

pub fn to_arrow(&mut self) -> PyResult<PyObject> {
self.rechunk(true);
Python::with_gil(|py| {
Expand Down

0 comments on commit b79dc8d

Please sign in to comment.