Skip to content

Commit

Permalink
remove deprecated methods (#2612)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Feb 11, 2022
1 parent dfac08d commit 5acad95
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 157 deletions.
15 changes: 0 additions & 15 deletions polars/polars-lazy/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,6 @@ impl LazyFrame {
self.select_local(vec![col("*").reverse()])
}

/// Rename a column in the DataFrame
#[deprecated(note = "use rename")]
pub fn with_column_renamed(self, existing_name: &str, new_name: &str) -> Self {
self.rename([existing_name], [new_name])
}

/// Rename columns in the DataFrame.
pub fn rename<I, J, T, S>(self, existing: I, new: J) -> Self
where
Expand Down Expand Up @@ -873,15 +867,6 @@ impl LazyFrame {
Self::from_logical_plan(lp, opt_state)
}

/// Drop duplicate rows. [See eager](polars_core::prelude::DataFrame::drop_duplicates).
#[deprecated(note = "use distinct")]
pub fn drop_duplicates(self, maintain_order: bool, subset: Option<Vec<String>>) -> LazyFrame {
match maintain_order {
true => self.distinct_stable(subset, DistinctKeepStrategy::First),
false => self.distinct(subset, DistinctKeepStrategy::First),
}
}

/// Keep unique rows and maintain order
pub fn distinct_stable(
self,
Expand Down
2 changes: 0 additions & 2 deletions py-polars/docs/source/reference/dataframe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,10 @@ Manipulation/ selection
DataFrame.groupby_rolling
DataFrame.select
DataFrame.with_columns
DataFrame.with_column_renamed
DataFrame.sample
DataFrame.row
DataFrame.rows
DataFrame.to_dummies
DataFrame.drop_duplicates
DataFrame.distinct
DataFrame.shrink_to_fit
DataFrame.rechunk
Expand Down
1 change: 0 additions & 1 deletion py-polars/docs/source/reference/expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ Manipulation/ selection
Expr.to_physical
Expr.shuffle
Expr.extend_constant
Expr.extend

Column names
------------
Expand Down
2 changes: 0 additions & 2 deletions py-polars/docs/source/reference/lazyframe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Manipulation/ selection
LazyFrame.join
LazyFrame.with_columns
LazyFrame.with_column
LazyFrame.with_column_renamed
LazyFrame.drop
LazyFrame.rename
LazyFrame.reverse
Expand All @@ -56,7 +55,6 @@ Manipulation/ selection
LazyFrame.fill_null
LazyFrame.fill_nan
LazyFrame.explode
LazyFrame.drop_duplicates
LazyFrame.distinct
LazyFrame.drop_nulls
LazyFrame.sort
Expand Down
1 change: 0 additions & 1 deletion py-polars/docs/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ Manipulation/ selection
Series.to_dummies
Series.shuffle
Series.extend_constant
Series.extend

Various
--------
Expand Down
18 changes: 1 addition & 17 deletions py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2298,36 +2298,20 @@ def ewm_var(
alpha = _prepare_alpha(com, span, half_life, alpha)
return wrap_expr(self._pyexpr.ewm_var(alpha, adjust, min_periods))

def extend(self, value: Optional[Union[int, float, str, bool]], n: int) -> "Expr":
"""
Extend the Series with given number of values.
Parameters
----------
value
The value to extend the Series with. This value may be None to fill with nulls.
n
The number of values to extend.
"""
return wrap_expr(self._pyexpr.extend_constant(value, n))

def extend_constant(
self, value: Optional[Union[int, float, str, bool]], n: int
) -> "Expr":
"""
Extend the Series with given number of values.
.. deprecated::0.12.21
use extend_constant
Parameters
----------
value
The value to extend the Series with. This value may be None to fill with nulls.
n
The number of values to extend.
"""
return self.extend_constant(value, n)
return wrap_expr(self._pyexpr.extend_constant(value, n))

# Below are the namespaces defined. Keep these at the end of the definition of Expr, as to not confuse mypy with
# the type annotation `str` with the namespace "str"
Expand Down
55 changes: 0 additions & 55 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2398,9 +2398,6 @@ def groupby_rolling(
- **"1i" # length 1**
- **"10i" # length 10**
.. warning::
This API is experimental and may change without it being considered a breaking change.
Parameters
----------
index_column
Expand Down Expand Up @@ -2517,9 +2514,6 @@ def groupby_dynamic(
- "1i" # length 1
- "10i" # length 10
.. warning::
This API is experimental and may change without it being considered a breaking change.
Parameters
----------
index_column
Expand Down Expand Up @@ -2789,9 +2783,6 @@ def upsample(
"""
Upsample a DataFrame at a regular frequency.
.. warning::
This API is experimental and may change without it being considered a breaking change.
Parameters
----------
time_column
Expand Down Expand Up @@ -3065,37 +3056,6 @@ def with_column(self, column: Union["pli.Series", "pli.Expr"]) -> "DataFrame":
else:
return wrap_df(self._df.with_column(column._s))

def with_column_renamed(self, existing_name: str, new_name: str) -> "DataFrame":
"""
Return a new DataFrame with the column renamed.
Parameters
----------
existing_name
new_name
Examples
--------
>>> df = pl.DataFrame({"a": [1, 2], "b": [3, 4]})
>>> df.with_column_renamed("b", "c")
shape: (2, 2)
┌─────┬─────┐
│ a ┆ c │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1 ┆ 3 │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 2 ┆ 4 │
└─────┴─────┘
"""
return (
self.lazy()
.with_column_renamed(existing_name, new_name)
.collect(no_optimization=True, string_cache=False)
)

def hstack(
self, columns: Union[List["pli.Series"], "DataFrame"], in_place: bool = False
) -> Optional["DataFrame"]:
Expand Down Expand Up @@ -4081,21 +4041,6 @@ def to_dummies(self) -> "DataFrame":
"""
return wrap_df(self._df.to_dummies())

def drop_duplicates(
self,
maintain_order: bool = True,
subset: Optional[Union[str, List[str]]] = None,
) -> "DataFrame":
"""
.. deprecated:: 0.12.18
Use :func:`DataFrame.distinct`
Drop duplicate rows from this DataFrame.
Note that this fails if there is a column of type `List` in the DataFrame.
"""
return self.distinct(maintain_order, subset, "first")

def distinct(
self,
maintain_order: bool = True,
Expand Down
30 changes: 0 additions & 30 deletions py-polars/polars/internals/lazy_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,6 @@ def groupby_rolling(
- "1i" # length 1
- "10i" # length 10
.. warning::
This API is experimental and may change without it being considered a breaking change.
Parameters
----------
index_column
Expand Down Expand Up @@ -744,9 +741,6 @@ def groupby_dynamic(
- "1i" # length 1
- "10i" # length 10
.. warning::
This API is experimental and may change without it being considered a breaking change.
Parameters
----------
index_column
Expand Down Expand Up @@ -980,15 +974,6 @@ def drop(self, columns: Union[str, List[str]]) -> "LazyFrame":
columns = [columns]
return wrap_ldf(self._ldf.drop_columns(columns))

def with_column_renamed(self, existing_name: str, new_name: str) -> "LazyFrame":
"""
.. deprecated:: 0.12.13
Use :func:rename instead
Rename a column in the DataFrame
"""
return wrap_ldf(self._ldf.with_column_renamed(existing_name, new_name))

def rename(self, mapping: Dict[str, str]) -> "LazyFrame":
"""
Rename column names.
Expand Down Expand Up @@ -1263,21 +1248,6 @@ def explode(
columns = pli.selection_to_pyexpr_list(columns)
return wrap_ldf(self._ldf.explode(columns))

def drop_duplicates(
self,
maintain_order: bool = False,
subset: Optional[Union[List[str], str]] = None,
) -> "LazyFrame":
"""
.. deprecated:: 0.12.18
Use :func:`DataFrame.distinct`
Drop duplicate rows from this DataFrame.
Note that this fails if there is a column of type `List` in the DataFrame.
"""
return self.distinct(maintain_order, subset, "first")

def distinct(
self,
maintain_order: bool = True,
Expand Down
16 changes: 0 additions & 16 deletions py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3424,22 +3424,6 @@ def extend_constant(
"""
return wrap_s(self._s.extend_constant(value, n))

def extend(self, value: Optional[Union[int, float, str, bool]], n: int) -> "Series":
"""
Extend the Series with given number of values.
.. deprecated::0.12.21
use extend_constant
Parameters
----------
value
The value to extend the Series with. This value may be None to fill with nulls.
n
The number of values to extend.
"""
return self.extend_constant(value, n)

@property
def time_unit(self) -> Optional[str]:
"""
Expand Down
5 changes: 0 additions & 5 deletions py-polars/src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,6 @@ impl PyLazyFrame {
ldf.rename(existing, new).into()
}

pub fn with_column_renamed(&mut self, existing: &str, new: &str) -> PyLazyFrame {
let ldf = self.ldf.clone();
ldf.with_column_renamed(existing, new).into()
}

pub fn reverse(&self) -> Self {
let ldf = self.ldf.clone();
ldf.reverse().into()
Expand Down
8 changes: 4 additions & 4 deletions py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,12 +1267,12 @@ def test_hashing_on_python_objects() -> None:
df = pl.DataFrame({"a": [1, 1, 3, 4], "b": [1, 1, 2, 2]})
df = df.with_column(pl.col("a").apply(lambda x: datetime(2021, 1, 1)).alias("foo"))
assert df.groupby(["foo"]).first().shape == (1, 3)
assert df.drop_duplicates().shape == (3, 3)
assert df.distinct().shape == (3, 3)


def test_drop_duplicates_unit_rows() -> None:
def test_distinct_unit_rows() -> None:
# simply test if we don't panic.
pl.DataFrame({"a": [1], "b": [None]}).drop_duplicates(subset="a")
pl.DataFrame({"a": [1], "b": [None]}).distinct(subset="a")


def test_panic() -> None:
Expand Down Expand Up @@ -1618,7 +1618,7 @@ def test_empty_projection() -> None:

def test_with_column_renamed() -> None:
df = pl.DataFrame({"a": [1, 2], "b": [3, 4]})
result = df.with_column_renamed("b", "c")
result = df.rename({"b": "c"})
expected = pl.DataFrame({"a": [1, 2], "c": [3, 4]})
assert result.frame_equal(expected)

Expand Down
10 changes: 4 additions & 6 deletions py-polars/tests/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ def test_drop_columns() -> None:


def test_with_column_renamed(fruits_cars: pl.DataFrame) -> None:
res = fruits_cars.lazy().with_column_renamed("A", "C").collect()
res = fruits_cars.lazy().rename({"A": "C"}).collect()
assert res.columns[0] == "C"


Expand Down Expand Up @@ -1093,18 +1093,16 @@ def test_is_between(fruits_cars: pl.DataFrame) -> None:
)


def test_drop_duplicates() -> None:
def test_distinct() -> None:
df = pl.DataFrame({"a": [1, 2, 2], "b": [3, 3, 3]})

expected = pl.DataFrame({"a": [1, 2], "b": [3, 3]})
assert (
df.lazy().drop_duplicates(maintain_order=True).collect().frame_equal(expected)
)
assert df.lazy().distinct(maintain_order=True).collect().frame_equal(expected)

expected = pl.DataFrame({"a": [1], "b": [3]})
assert (
df.lazy()
.drop_duplicates(subset="b", maintain_order=True)
.distinct(subset="b", maintain_order=True)
.collect()
.frame_equal(expected)
)
Expand Down
6 changes: 3 additions & 3 deletions py-polars/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,13 +1387,13 @@ def test_ewm_std_var() -> None:
assert (a.ewm_std(alpha=0.5) ** 2).to_list() == a.ewm_var(alpha=0.5).to_list()


def test_extend() -> None:
def test_extend_constant() -> None:
a = pl.Series("a", [1, 2, 3])
expected = pl.Series("a", [1, 2, 3, 1, 1, 1])
verify_series_and_expr_api(a, expected, "extend", 1, 3)
verify_series_and_expr_api(a, expected, "extend_constant", 1, 3)

expected = pl.Series("a", [1, 2, 3, None, None, None])
verify_series_and_expr_api(a, expected, "extend", None, 3)
verify_series_and_expr_api(a, expected, "extend_constant", None, 3)


def test_any_all() -> None:
Expand Down

0 comments on commit 5acad95

Please sign in to comment.