Skip to content

Commit

Permalink
MAINT: Drop take_last kwarg from method signatures
Browse files Browse the repository at this point in the history
Affected methods:

1) nlargest
2) nsmallest
3) duplicated
4) drop_duplicates

xref #10236, #10792, #10920.

Author: gfyoung <gfyoung17@gmail.com>

Closes #15710 from gfyoung/create-last-kw-drop and squashes the following commits:

b416290 [gfyoung] MAINT: Drop take_last kwarg from method signatures
  • Loading branch information
gfyoung authored and jreback committed Mar 18, 2017
1 parent 5e96fb0 commit a9c8239
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 209 deletions.
12 changes: 6 additions & 6 deletions asv_bench/benchmarks/series_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def setup(self):
self.s4 = self.s3.astype('object')

def time_series_nlargest1(self):
self.s1.nlargest(3, take_last=True)
self.s1.nlargest(3, take_last=False)
self.s1.nlargest(3, keep='last')
self.s1.nlargest(3, keep='first')


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

def time_series_nlargest2(self):
self.s2.nlargest(3, take_last=True)
self.s2.nlargest(3, take_last=False)
self.s2.nlargest(3, keep='last')
self.s2.nlargest(3, keep='first')


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

def time_series_nsmallest2(self):
self.s2.nsmallest(3, take_last=True)
self.s2.nsmallest(3, take_last=False)
self.s2.nsmallest(3, keep='last')
self.s2.nsmallest(3, keep='first')


class series_dropna_int64(object):
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ Removal of prior version deprecations/changes
in favor of ``iloc`` and ``iat`` as explained :ref:`here <whatsnew_0170.deprecations>` (:issue:`10711`).
- The deprecated ``DataFrame.iterkv()`` has been removed in favor of ``DataFrame.iteritems()`` (:issue:`10711`)
- The ``Categorical`` constructor has dropped the ``name`` parameter (:issue:`10632`)
- The ``take_last`` parameter has been dropped from ``duplicated()``, ``drop_duplicates()``, ``nlargest()``, and ``nsmallest()`` methods (:issue:`10236`, :issue:`10792`, :issue:`10920`)

.. _whatsnew_0200.performance:

Expand Down
6 changes: 0 additions & 6 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,16 +1065,13 @@ def searchsorted(self, value, side='left', sorter=None):
- ``first`` : Drop duplicates except for the first occurrence.
- ``last`` : Drop duplicates except for the last occurrence.
- False : Drop all duplicates.
take_last : deprecated
%(inplace)s
Returns
-------
deduplicated : %(klass)s
""")

@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
False: 'first'})
@Appender(_shared_docs['drop_duplicates'] % _indexops_doc_kwargs)
def drop_duplicates(self, keep='first', inplace=False):
inplace = validate_bool_kwarg(inplace, 'inplace')
Expand All @@ -1100,15 +1097,12 @@ def drop_duplicates(self, keep='first', inplace=False):
- ``last`` : Mark duplicates as ``True`` except for the last
occurrence.
- False : Mark all duplicates as ``True``.
take_last : deprecated
Returns
-------
duplicated : %(duplicated)s
""")

@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
False: 'first'})
@Appender(_shared_docs['duplicated'] % _indexops_doc_kwargs)
def duplicated(self, keep='first'):
from pandas.core.algorithms import duplicated
Expand Down
9 changes: 1 addition & 8 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
OrderedDict, raise_with_traceback)
from pandas import compat
from pandas.compat.numpy import function as nv
from pandas.util.decorators import (deprecate_kwarg, Appender,
Substitution)
from pandas.util.decorators import Appender, Substitution
from pandas.util.validators import validate_bool_kwarg

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

@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
False: 'first'})
def drop_duplicates(self, subset=None, keep='first', inplace=False):
"""
Return DataFrame with duplicate rows removed, optionally only
Expand All @@ -3185,7 +3182,6 @@ def drop_duplicates(self, subset=None, keep='first', inplace=False):
- ``first`` : Drop duplicates except for the first occurrence.
- ``last`` : Drop duplicates except for the last occurrence.
- False : Drop all duplicates.
take_last : deprecated
inplace : boolean, default False
Whether to drop duplicates in place or to return a copy
Expand All @@ -3203,8 +3199,6 @@ def drop_duplicates(self, subset=None, keep='first', inplace=False):
else:
return self[-duplicated]

@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
False: 'first'})
def duplicated(self, subset=None, keep='first'):
"""
Return boolean Series denoting duplicate rows, optionally only
Expand All @@ -3221,7 +3215,6 @@ def duplicated(self, subset=None, keep='first'):
- ``last`` : Mark duplicates as ``True`` except for the
last occurrence.
- False : Mark all duplicates as ``True``.
take_last : deprecated
Returns
-------
Expand Down
28 changes: 7 additions & 21 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
from pandas.core.sorting import (get_group_index_sorter, get_group_index,
compress_group_index, get_flattened_iterator,
decons_obs_group_ids, get_indexer_dict)
from pandas.util.decorators import (cache_readonly, Substitution, Appender,
make_signature, deprecate_kwarg)
from pandas.util.decorators import (cache_readonly, Substitution,
Appender, make_signature)
from pandas.formats.printing import pprint_thing
from pandas.util.validators import validate_kwargs

Expand Down Expand Up @@ -94,12 +94,12 @@
'corr', 'cov', 'diff',
]) | _plotting_methods

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

_dataframe_apply_whitelist = \
_common_apply_whitelist | frozenset(['dtypes', 'corrwith'])
_dataframe_apply_whitelist = (_common_apply_whitelist |
frozenset(['dtypes', 'corrwith']))

_cython_transforms = frozenset(['cumprod', 'cumsum', 'shift',
'cummin', 'cummax'])
Expand Down Expand Up @@ -3025,20 +3025,6 @@ def nunique(self, dropna=True):
index=ri,
name=self.name)

@deprecate_kwarg('take_last', 'keep',
mapping={True: 'last', False: 'first'})
@Appender(Series.nlargest.__doc__)
def nlargest(self, n=5, keep='first'):
# ToDo: When we remove deprecate_kwargs, we can remote these methods
# and include nlargest and nsmallest to _series_apply_whitelist
return self.apply(lambda x: x.nlargest(n=n, keep=keep))

@deprecate_kwarg('take_last', 'keep',
mapping={True: 'last', False: 'first'})
@Appender(Series.nsmallest.__doc__)
def nsmallest(self, n=5, keep='first'):
return self.apply(lambda x: x.nsmallest(n=n, keep=keep))

@Appender(Series.describe.__doc__)
def describe(self, **kwargs):
self._set_group_selection()
Expand Down
10 changes: 0 additions & 10 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,14 +1211,10 @@ def unique(self):
return result.asobject.values
return result

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

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

@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
False: 'first'})
def nlargest(self, n=5, keep='first'):
"""Return the largest `n` elements.
Expand All @@ -1901,7 +1895,6 @@ def nlargest(self, n=5, keep='first'):
Where there are duplicate values:
- ``first`` : take the first occurrence.
- ``last`` : take the last occurrence.
take_last : deprecated
Returns
-------
Expand Down Expand Up @@ -1938,8 +1931,6 @@ def nlargest(self, n=5, keep='first'):
return algorithms.select_n_series(self, n=n, keep=keep,
method='nlargest')

@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
False: 'first'})
def nsmallest(self, n=5, keep='first'):
"""Return the smallest `n` elements.
Expand All @@ -1951,7 +1942,6 @@ def nsmallest(self, n=5, keep='first'):
Where there are duplicate values:
- ``first`` : take the first occurrence.
- ``last`` : take the last occurrence.
take_last : deprecated
Returns
-------
Expand Down
4 changes: 0 additions & 4 deletions pandas/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3500,14 +3500,10 @@ def unique(self):
result = super(Index, self).unique()
return self._shallow_copy(result)

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

@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
False: 'first'})
@Appender(base._shared_docs['duplicated'] % _index_doc_kwargs)
def duplicated(self, keep='first'):
return super(Index, self).duplicated(keep=keep)
Expand Down
5 changes: 1 addition & 4 deletions pandas/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
from pandas.types.missing import array_equivalent


from pandas.util.decorators import (Appender, cache_readonly,
deprecate_kwarg)
from pandas.util.decorators import Appender, cache_readonly
from pandas.core.config import get_option
from pandas.indexes.base import Index, _index_shared_docs
import pandas.core.base as base
Expand Down Expand Up @@ -301,8 +300,6 @@ def unique(self):
return self._shallow_copy(result, categories=result.categories,
ordered=result.ordered)

@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
False: 'first'})
@Appender(base._shared_docs['duplicated'] % _index_doc_kwargs)
def duplicated(self, keep='first'):
from pandas._libs.hashtable import duplicated_int64
Expand Down
2 changes: 0 additions & 2 deletions pandas/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,6 @@ def f(k, stringify):
for k, stringify in zip(key, self._have_mixed_levels)])
return hash_tuples(key)

@deprecate_kwarg('take_last', 'keep', mapping={True: 'last',
False: 'first'})
@Appender(base._shared_docs['duplicated'] % _index_doc_kwargs)
def duplicated(self, keep='first'):
from pandas.core.sorting import get_group_index
Expand Down
Loading

0 comments on commit a9c8239

Please sign in to comment.