Skip to content

Commit 2b0cbf2

Browse files
natmokvalmroeschke
authored andcommitted
CLN: enforce the deprecation of the Series.argsort NA behavior (pandas-dev#58232)
* enforce deprecation of the Series.argsort NA behavior * remove comments * add a note to v3.0.0 * correct def argsort and tests * correct def argsort/tests * fix pre-commit error * Restore numpy test --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 2d6e61e commit 2b0cbf2

File tree

7 files changed

+64
-39
lines changed

7 files changed

+64
-39
lines changed

das as pd.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pandas as pd
2+
3+
# 데이터 프레임 생성
4+
data = {
5+
"항목": ["Initial Cost", "Annual Operating Cost", "Annual Revenue", "Proud Number"],
6+
"값": [1000000, 200000, 400000, "=B4/(B2+B3)"]
7+
}
8+
9+
df = pd.DataFrame(data)
10+
11+
# 엑셀 파일로 저장
12+
file_path = "/mnt/data/Proud_Number_Calculation.xlsx"
13+
df.to_excel(file_path, index=False)
14+
15+
import ace_tools as tools; tools.display_dataframe_to_user(name="Proud Number Calculation", dataframe=df)

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ Other Removals
382382
- Enforced deprecation of strings ``T``, ``L``, ``U``, and ``N`` denoting units in :class:`Timedelta` (:issue:`57627`)
383383
- Enforced deprecation of the behavior of :func:`concat` when ``len(keys) != len(objs)`` would truncate to the shorter of the two. Now this raises a ``ValueError`` (:issue:`43485`)
384384
- Enforced deprecation of the behavior of :meth:`DataFrame.replace` and :meth:`Series.replace` with :class:`CategoricalDtype` that would introduce new categories. (:issue:`58270`)
385+
- Enforced deprecation of the behavior of :meth:`Series.argsort` in the presence of NA values (:issue:`58232`)
385386
- Enforced deprecation of values "pad", "ffill", "bfill", and "backfill" for :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` (:issue:`57869`)
386387
- Enforced deprecation removing :meth:`Categorical.to_list`, use ``obj.tolist()`` instead (:issue:`51254`)
387388
- Enforced silent-downcasting deprecation for :ref:`all relevant methods <whatsnew_220.silent_downcasting>` (:issue:`54710`)

import pandas as pd.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pandas as pd
2+
3+
# 데이터 프레임 생성
4+
data = {
5+
"Component": ["Displacement (lbs)", "Waterline Length (Lwl) (ft)", "Displacement/Length Ratio"],
6+
"Value": [20000, 35, "=(B2/2240)/((B3/100)^3)"]
7+
}
8+
9+
df = pd.DataFrame(data)
10+
11+
# 엑셀 파일로 저장
12+
file_path = "/mnt/data/Displacement_Length_Ratio_Calculation.xlsx"
13+
df.to_excel(file_path, index=False)
14+
15+
import ace_tools as tools; tools.display_dataframe_to_user(name="Displacement/Length Ratio Calculation", dataframe=df)

pandas/core/series.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
deprecate_nonkeyword_arguments,
5050
doc,
5151
)
52-
from pandas.util._exceptions import find_stack_level
5352
from pandas.util._validators import (
5453
validate_ascending,
5554
validate_bool_kwarg,
@@ -3722,25 +3721,7 @@ def argsort(
37223721
# GH#54257 We allow -1 here so that np.argsort(series) works
37233722
self._get_axis_number(axis)
37243723

3725-
values = self._values
3726-
mask = isna(values)
3727-
3728-
if mask.any():
3729-
# TODO(3.0): once this deprecation is enforced we can call
3730-
# self.array.argsort directly, which will close GH#43840 and
3731-
# GH#12694
3732-
warnings.warn(
3733-
"The behavior of Series.argsort in the presence of NA values is "
3734-
"deprecated. In a future version, NA values will be ordered "
3735-
"last instead of set to -1.",
3736-
FutureWarning,
3737-
stacklevel=find_stack_level(),
3738-
)
3739-
result = np.full(len(self), -1, dtype=np.intp)
3740-
notmask = ~mask
3741-
result[notmask] = np.argsort(values[notmask], kind=kind)
3742-
else:
3743-
result = np.argsort(values, kind=kind)
3724+
result = self.array.argsort(kind=kind)
37443725

37453726
res = self._constructor(
37463727
result, index=self.index, name=self.name, dtype=np.intp, copy=False

pandas/tests/extension/base/methods.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ def test_argsort_missing_array(self, data_missing_for_sorting):
116116
tm.assert_numpy_array_equal(result, expected)
117117

118118
def test_argsort_missing(self, data_missing_for_sorting):
119-
msg = "The behavior of Series.argsort in the presence of NA values"
120-
with tm.assert_produces_warning(FutureWarning, match=msg):
121-
result = pd.Series(data_missing_for_sorting).argsort()
122-
expected = pd.Series(np.array([1, -1, 0], dtype=np.intp))
119+
result = pd.Series(data_missing_for_sorting).argsort()
120+
expected = pd.Series(np.array([2, 0, 1], dtype=np.intp))
123121
tm.assert_series_equal(result, expected)
124122

125123
def test_argmin_argmax(self, data_for_sorting, data_missing_for_sorting, na_value):

pandas/tests/series/methods/test_argsort.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,15 @@ def test_argsort_axis(self):
2020

2121
def test_argsort_numpy(self, datetime_series):
2222
ser = datetime_series
23-
2423
res = np.argsort(ser).values
2524
expected = np.argsort(np.array(ser))
2625
tm.assert_numpy_array_equal(res, expected)
2726

28-
# with missing values
29-
ts = ser.copy()
30-
ts[::2] = np.nan
31-
32-
msg = "The behavior of Series.argsort in the presence of NA values"
33-
with tm.assert_produces_warning(
34-
FutureWarning, match=msg, check_stacklevel=False
35-
):
36-
result = np.argsort(ts)[1::2]
37-
expected = np.argsort(np.array(ts.dropna()))
27+
def test_argsort_numpy_missing(self):
28+
data = [0.1, np.nan, 0.2, np.nan, 0.3]
29+
ser = Series(data)
30+
result = np.argsort(ser)
31+
expected = np.argsort(np.array(data))
3832

3933
tm.assert_numpy_array_equal(result.values, expected)
4034

@@ -56,10 +50,8 @@ def test_argsort_dt64(self, unit):
5650
expected = Series(range(5), dtype=np.intp)
5751
tm.assert_series_equal(result, expected)
5852

59-
msg = "The behavior of Series.argsort in the presence of NA values"
60-
with tm.assert_produces_warning(FutureWarning, match=msg):
61-
result = shifted.argsort()
62-
expected = Series(list(range(4)) + [-1], dtype=np.intp)
53+
result = shifted.argsort()
54+
expected = Series(list(range(4)) + [4], dtype=np.intp)
6355
tm.assert_series_equal(result, expected)
6456

6557
def test_argsort_stable(self):

sdtesdg.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pandas as pd
2+
3+
# 데이터 프레임 생성
4+
data = {
5+
"Component": [
6+
"Length Overall (LOA) (ft)", "Beam (ft)", "Draft (ft)", "Displacement (lbs)",
7+
"Waterline Length (Lwl) (ft)", "Speed (knots)", "Fuel Consumption (gallons/hour)",
8+
"Length-to-Beam Ratio", "Beam-to-Draft Ratio", "Displacement/Length Ratio",
9+
"Prismatic Coefficient (Cp)", "Speed-to-Length Ratio", "Fuel Consumption per Mile"
10+
],
11+
"Value": [
12+
40, 12, 4, 20000, 35, 10, 20, "=B2/B3", "=B3/B4",
13+
"=(B5/2240)/((B6/100)^3)", "=0.6", "=B7/SQRT(B6)", "=B8/B7"
14+
]
15+
}
16+
17+
df = pd.DataFrame(data)
18+
19+
# 엑셀 파일로 저장
20+
file_path = "/mnt/data/Powerboat_Coastal_Cruising_Ratio_Calculation.xlsx"
21+
df.to_excel(file_path, index=False)
22+
23+
import pandas as pd; tools.display_dataframe_to_user(name="Powerboat Coastal Cruising Ratio Calculation", dataframe=df)

0 commit comments

Comments
 (0)