Skip to content

Commit

Permalink
fix(python): Fix Series.argsort (#7183)
Browse files Browse the repository at this point in the history
  • Loading branch information
zundertj authored Feb 25, 2023
1 parent e6b9930 commit 488cba7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions py-polars/polars/internals/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import math
import os
import typing
import warnings
from datetime import date, datetime, time, timedelta
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -2048,6 +2049,12 @@ def argsort(self, descending: bool = False, nulls_last: bool = False) -> Series:
Place null values last instead of first.
"""
warnings.warn(
"`Series.argsort()` is deprecated in favor of `Series.arg_sort()`",
DeprecationWarning,
stacklevel=2,
)
return self.arg_sort(descending, nulls_last)

def arg_unique(self) -> Series:
"""
Expand Down
11 changes: 11 additions & 0 deletions py-polars/tests/unit/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,17 @@ def test_arg_sort() -> None:
assert_series_equal(s.arg_sort(descending=True), expected_descending)


def test_argsort_deprecated() -> None:
s = pl.Series("a", [5, 3, 4, 1, 2])
expected = pl.Series("a", [3, 4, 1, 2, 0], dtype=UInt32)
with pytest.deprecated_call():
assert_series_equal(s.argsort(), expected)

expected_descending = pl.Series("a", [0, 2, 1, 4, 3], dtype=UInt32)
with pytest.deprecated_call():
assert_series_equal(s.argsort(descending=True), expected_descending)


def test_arg_min_and_arg_max() -> None:
s = pl.Series("a", [5, 3, 4, 1, 2])
assert s.arg_min() == 3
Expand Down

0 comments on commit 488cba7

Please sign in to comment.