Skip to content

Commit b416290

Browse files
committed
MAINT: Drop take_last kwarg from method signatures
Affected methods: 1) nlargest 2) nsmallest 3) duplicated 4) drop_duplicates xref gh-10236, gh-10792, gh-10920.
1 parent de17fd9 commit b416290

File tree

15 files changed

+26
-209
lines changed

15 files changed

+26
-209
lines changed

asv_bench/benchmarks/series_methods.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def setup(self):
6868
self.s4 = self.s3.astype('object')
6969

7070
def time_series_nlargest1(self):
71-
self.s1.nlargest(3, take_last=True)
72-
self.s1.nlargest(3, take_last=False)
71+
self.s1.nlargest(3, keep='last')
72+
self.s1.nlargest(3, keep='first')
7373

7474

7575
class series_nlargest2(object):
@@ -83,8 +83,8 @@ def setup(self):
8383
self.s4 = self.s3.astype('object')
8484

8585
def time_series_nlargest2(self):
86-
self.s2.nlargest(3, take_last=True)
87-
self.s2.nlargest(3, take_last=False)
86+
self.s2.nlargest(3, keep='last')
87+
self.s2.nlargest(3, keep='first')
8888

8989

9090
class series_nsmallest2(object):
@@ -98,8 +98,8 @@ def setup(self):
9898
self.s4 = self.s3.astype('object')
9999

100100
def time_series_nsmallest2(self):
101-
self.s2.nsmallest(3, take_last=True)
102-
self.s2.nsmallest(3, take_last=False)
101+
self.s2.nsmallest(3, keep='last')
102+
self.s2.nsmallest(3, keep='first')
103103

104104

105105
class series_dropna_int64(object):

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ Removal of prior version deprecations/changes
769769
in favor of ``iloc`` and ``iat`` as explained :ref:`here <whatsnew_0170.deprecations>` (:issue:`10711`).
770770
- The deprecated ``DataFrame.iterkv()`` has been removed in favor of ``DataFrame.iteritems()`` (:issue:`10711`)
771771
- The ``Categorical`` constructor has dropped the ``name`` parameter (:issue:`10632`)
772+
- The ``take_last`` parameter has been dropped from ``duplicated()``, ``drop_duplicates()``, ``nlargest()``, and ``nsmallest()`` methods (:issue:`10236`, :issue:`10792`, :issue:`10920`)
772773

773774
.. _whatsnew_0200.performance:
774775

pandas/core/base.py

-6
Original file line numberDiff line numberDiff line change
@@ -1065,16 +1065,13 @@ def searchsorted(self, value, side='left', sorter=None):
10651065
- ``first`` : Drop duplicates except for the first occurrence.
10661066
- ``last`` : Drop duplicates except for the last occurrence.
10671067
- False : Drop all duplicates.
1068-
take_last : deprecated
10691068
%(inplace)s
10701069
10711070
Returns
10721071
-------
10731072
deduplicated : %(klass)s
10741073
""")
10751074

1076-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
1077-
False: 'first'})
10781075
@Appender(_shared_docs['drop_duplicates'] % _indexops_doc_kwargs)
10791076
def drop_duplicates(self, keep='first', inplace=False):
10801077
inplace = validate_bool_kwarg(inplace, 'inplace')
@@ -1100,15 +1097,12 @@ def drop_duplicates(self, keep='first', inplace=False):
11001097
- ``last`` : Mark duplicates as ``True`` except for the last
11011098
occurrence.
11021099
- False : Mark all duplicates as ``True``.
1103-
take_last : deprecated
11041100
11051101
Returns
11061102
-------
11071103
duplicated : %(duplicated)s
11081104
""")
11091105

1110-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
1111-
False: 'first'})
11121106
@Appender(_shared_docs['duplicated'] % _indexops_doc_kwargs)
11131107
def duplicated(self, keep='first'):
11141108
from pandas.core.algorithms import duplicated

pandas/core/frame.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@
7777
OrderedDict, raise_with_traceback)
7878
from pandas import compat
7979
from pandas.compat.numpy import function as nv
80-
from pandas.util.decorators import (deprecate_kwarg, Appender,
81-
Substitution)
80+
from pandas.util.decorators import Appender, Substitution
8281
from pandas.util.validators import validate_bool_kwarg
8382

8483
from pandas.tseries.period import PeriodIndex
@@ -3169,8 +3168,6 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
31693168
else:
31703169
return result
31713170

3172-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
3173-
False: 'first'})
31743171
def drop_duplicates(self, subset=None, keep='first', inplace=False):
31753172
"""
31763173
Return DataFrame with duplicate rows removed, optionally only
@@ -3185,7 +3182,6 @@ def drop_duplicates(self, subset=None, keep='first', inplace=False):
31853182
- ``first`` : Drop duplicates except for the first occurrence.
31863183
- ``last`` : Drop duplicates except for the last occurrence.
31873184
- False : Drop all duplicates.
3188-
take_last : deprecated
31893185
inplace : boolean, default False
31903186
Whether to drop duplicates in place or to return a copy
31913187
@@ -3203,8 +3199,6 @@ def drop_duplicates(self, subset=None, keep='first', inplace=False):
32033199
else:
32043200
return self[-duplicated]
32053201

3206-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
3207-
False: 'first'})
32083202
def duplicated(self, subset=None, keep='first'):
32093203
"""
32103204
Return boolean Series denoting duplicate rows, optionally only
@@ -3221,7 +3215,6 @@ def duplicated(self, subset=None, keep='first'):
32213215
- ``last`` : Mark duplicates as ``True`` except for the
32223216
last occurrence.
32233217
- False : Mark all duplicates as ``True``.
3224-
take_last : deprecated
32253218
32263219
Returns
32273220
-------

pandas/core/groupby.py

+7-21
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
from pandas.core.sorting import (get_group_index_sorter, get_group_index,
5252
compress_group_index, get_flattened_iterator,
5353
decons_obs_group_ids, get_indexer_dict)
54-
from pandas.util.decorators import (cache_readonly, Substitution, Appender,
55-
make_signature, deprecate_kwarg)
54+
from pandas.util.decorators import (cache_readonly, Substitution,
55+
Appender, make_signature)
5656
from pandas.formats.printing import pprint_thing
5757
from pandas.util.validators import validate_kwargs
5858

@@ -94,12 +94,12 @@
9494
'corr', 'cov', 'diff',
9595
]) | _plotting_methods
9696

97-
_series_apply_whitelist = \
98-
(_common_apply_whitelist - set(['boxplot'])) | \
99-
frozenset(['dtype', 'unique'])
97+
_series_apply_whitelist = ((_common_apply_whitelist |
98+
{'nlargest', 'nsmallest'}) -
99+
{'boxplot'}) | frozenset(['dtype', 'unique'])
100100

101-
_dataframe_apply_whitelist = \
102-
_common_apply_whitelist | frozenset(['dtypes', 'corrwith'])
101+
_dataframe_apply_whitelist = (_common_apply_whitelist |
102+
frozenset(['dtypes', 'corrwith']))
103103

104104
_cython_transforms = frozenset(['cumprod', 'cumsum', 'shift',
105105
'cummin', 'cummax'])
@@ -3025,20 +3025,6 @@ def nunique(self, dropna=True):
30253025
index=ri,
30263026
name=self.name)
30273027

3028-
@deprecate_kwarg('take_last', 'keep',
3029-
mapping={True: 'last', False: 'first'})
3030-
@Appender(Series.nlargest.__doc__)
3031-
def nlargest(self, n=5, keep='first'):
3032-
# ToDo: When we remove deprecate_kwargs, we can remote these methods
3033-
# and include nlargest and nsmallest to _series_apply_whitelist
3034-
return self.apply(lambda x: x.nlargest(n=n, keep=keep))
3035-
3036-
@deprecate_kwarg('take_last', 'keep',
3037-
mapping={True: 'last', False: 'first'})
3038-
@Appender(Series.nsmallest.__doc__)
3039-
def nsmallest(self, n=5, keep='first'):
3040-
return self.apply(lambda x: x.nsmallest(n=n, keep=keep))
3041-
30423028
@Appender(Series.describe.__doc__)
30433029
def describe(self, **kwargs):
30443030
self._set_group_selection()

pandas/core/series.py

-10
Original file line numberDiff line numberDiff line change
@@ -1211,14 +1211,10 @@ def unique(self):
12111211
return result.asobject.values
12121212
return result
12131213

1214-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
1215-
False: 'first'})
12161214
@Appender(base._shared_docs['drop_duplicates'] % _shared_doc_kwargs)
12171215
def drop_duplicates(self, keep='first', inplace=False):
12181216
return super(Series, self).drop_duplicates(keep=keep, inplace=inplace)
12191217

1220-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
1221-
False: 'first'})
12221218
@Appender(base._shared_docs['duplicated'] % _shared_doc_kwargs)
12231219
def duplicated(self, keep='first'):
12241220
return super(Series, self).duplicated(keep=keep)
@@ -1888,8 +1884,6 @@ def argsort(self, axis=0, kind='quicksort', order=None):
18881884
np.argsort(values, kind=kind), index=self.index,
18891885
dtype='int64').__finalize__(self)
18901886

1891-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
1892-
False: 'first'})
18931887
def nlargest(self, n=5, keep='first'):
18941888
"""Return the largest `n` elements.
18951889
@@ -1901,7 +1895,6 @@ def nlargest(self, n=5, keep='first'):
19011895
Where there are duplicate values:
19021896
- ``first`` : take the first occurrence.
19031897
- ``last`` : take the last occurrence.
1904-
take_last : deprecated
19051898
19061899
Returns
19071900
-------
@@ -1938,8 +1931,6 @@ def nlargest(self, n=5, keep='first'):
19381931
return algorithms.select_n_series(self, n=n, keep=keep,
19391932
method='nlargest')
19401933

1941-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
1942-
False: 'first'})
19431934
def nsmallest(self, n=5, keep='first'):
19441935
"""Return the smallest `n` elements.
19451936
@@ -1951,7 +1942,6 @@ def nsmallest(self, n=5, keep='first'):
19511942
Where there are duplicate values:
19521943
- ``first`` : take the first occurrence.
19531944
- ``last`` : take the last occurrence.
1954-
take_last : deprecated
19551945
19561946
Returns
19571947
-------

pandas/indexes/base.py

-4
Original file line numberDiff line numberDiff line change
@@ -3500,14 +3500,10 @@ def unique(self):
35003500
result = super(Index, self).unique()
35013501
return self._shallow_copy(result)
35023502

3503-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
3504-
False: 'first'})
35053503
@Appender(base._shared_docs['drop_duplicates'] % _index_doc_kwargs)
35063504
def drop_duplicates(self, keep='first'):
35073505
return super(Index, self).drop_duplicates(keep=keep)
35083506

3509-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
3510-
False: 'first'})
35113507
@Appender(base._shared_docs['duplicated'] % _index_doc_kwargs)
35123508
def duplicated(self, keep='first'):
35133509
return super(Index, self).duplicated(keep=keep)

pandas/indexes/category.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
from pandas.types.missing import array_equivalent
1212

1313

14-
from pandas.util.decorators import (Appender, cache_readonly,
15-
deprecate_kwarg)
14+
from pandas.util.decorators import Appender, cache_readonly
1615
from pandas.core.config import get_option
1716
from pandas.indexes.base import Index, _index_shared_docs
1817
import pandas.core.base as base
@@ -301,8 +300,6 @@ def unique(self):
301300
return self._shallow_copy(result, categories=result.categories,
302301
ordered=result.ordered)
303302

304-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
305-
False: 'first'})
306303
@Appender(base._shared_docs['duplicated'] % _index_doc_kwargs)
307304
def duplicated(self, keep='first'):
308305
from pandas._libs.hashtable import duplicated_int64

pandas/indexes/multi.py

-2
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,6 @@ def f(k, stringify):
755755
for k, stringify in zip(key, self._have_mixed_levels)])
756756
return hash_tuples(key)
757757

758-
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
759-
False: 'first'})
760758
@Appender(base._shared_docs['duplicated'] % _index_doc_kwargs)
761759
def duplicated(self, keep='first'):
762760
from pandas.core.sorting import get_group_index

0 commit comments

Comments
 (0)