Skip to content

Commit

Permalink
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 pandas-devgh-10236, pandas-devgh-10792, pandas-devgh-10920.
  • Loading branch information
gfyoung committed Mar 16, 2017
1 parent 3cac2d5 commit 30372eb
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 182 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
6 changes: 0 additions & 6 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3169,8 +3169,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 +3183,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 +3200,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 +3216,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
6 changes: 1 addition & 5 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3025,16 +3025,12 @@ 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
# TODO: When we remove deprecate_kwargs, we can remove 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))
Expand Down
4 changes: 0 additions & 4 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
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
2 changes: 0 additions & 2 deletions pandas/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,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
75 changes: 0 additions & 75 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,12 +1381,6 @@ def test_drop_duplicates(self):
tm.assert_frame_equal(result, expected)
self.assertEqual(len(result), 0)

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
result = df.drop_duplicates('AAA', take_last=True)
expected = df.loc[[6, 7]]
tm.assert_frame_equal(result, expected)

# multi column
expected = df.loc[[0, 1, 2, 3]]
result = df.drop_duplicates(np.array(['AAA', 'B']))
Expand All @@ -1402,12 +1396,6 @@ def test_drop_duplicates(self):
expected = df.loc[[0]]
tm.assert_frame_equal(result, expected)

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
result = df.drop_duplicates(('AAA', 'B'), take_last=True)
expected = df.loc[[0, 5, 6, 7]]
tm.assert_frame_equal(result, expected)

# consider everything
df2 = df.loc[:, ['AAA', 'B', 'C']]

Expand All @@ -1424,13 +1412,6 @@ def test_drop_duplicates(self):
expected = df2.drop_duplicates(['AAA', 'B'], keep=False)
tm.assert_frame_equal(result, expected)

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
result = df2.drop_duplicates(take_last=True)
with tm.assert_produces_warning(FutureWarning):
expected = df2.drop_duplicates(['AAA', 'B'], take_last=True)
tm.assert_frame_equal(result, expected)

# integers
result = df.drop_duplicates('C')
expected = df.iloc[[0, 2]]
Expand Down Expand Up @@ -1529,12 +1510,6 @@ def test_drop_duplicates_tuple(self):
self.assertEqual(len(result), 0)
tm.assert_frame_equal(result, expected)

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
result = df.drop_duplicates(('AA', 'AB'), take_last=True)
expected = df.loc[[6, 7]]
tm.assert_frame_equal(result, expected)

# multi column
expected = df.loc[[0, 1, 2, 3]]
result = df.drop_duplicates((('AA', 'AB'), 'B'))
Expand Down Expand Up @@ -1563,12 +1538,6 @@ def test_drop_duplicates_NA(self):
tm.assert_frame_equal(result, expected)
self.assertEqual(len(result), 0)

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
result = df.drop_duplicates('A', take_last=True)
expected = df.loc[[1, 6, 7]]
tm.assert_frame_equal(result, expected)

# multi column
result = df.drop_duplicates(['A', 'B'])
expected = df.loc[[0, 2, 3, 6]]
Expand All @@ -1582,12 +1551,6 @@ def test_drop_duplicates_NA(self):
expected = df.loc[[6]]
tm.assert_frame_equal(result, expected)

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
result = df.drop_duplicates(['A', 'B'], take_last=True)
expected = df.loc[[1, 5, 6, 7]]
tm.assert_frame_equal(result, expected)

# nan
df = DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'bar', 'foo'],
Expand All @@ -1610,12 +1573,6 @@ def test_drop_duplicates_NA(self):
tm.assert_frame_equal(result, expected)
self.assertEqual(len(result), 0)

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
result = df.drop_duplicates('C', take_last=True)
expected = df.loc[[3, 7]]
tm.assert_frame_equal(result, expected)

# multi column
result = df.drop_duplicates(['C', 'B'])
expected = df.loc[[0, 1, 2, 4]]
Expand All @@ -1629,12 +1586,6 @@ def test_drop_duplicates_NA(self):
expected = df.loc[[1]]
tm.assert_frame_equal(result, expected)

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
result = df.drop_duplicates(['C', 'B'], take_last=True)
expected = df.loc[[1, 3, 6, 7]]
tm.assert_frame_equal(result, expected)

def test_drop_duplicates_NA_for_take_all(self):
# none
df = DataFrame({'A': [None, None, 'foo', 'bar',
Expand Down Expand Up @@ -1697,14 +1648,6 @@ def test_drop_duplicates_inplace(self):
tm.assert_frame_equal(result, expected)
self.assertEqual(len(df), 0)

# deprecate take_last
df = orig.copy()
with tm.assert_produces_warning(FutureWarning):
df.drop_duplicates('A', take_last=True, inplace=True)
expected = orig.loc[[6, 7]]
result = df
tm.assert_frame_equal(result, expected)

# multi column
df = orig.copy()
df.drop_duplicates(['A', 'B'], inplace=True)
Expand All @@ -1724,14 +1667,6 @@ def test_drop_duplicates_inplace(self):
result = df
tm.assert_frame_equal(result, expected)

# deprecate take_last
df = orig.copy()
with tm.assert_produces_warning(FutureWarning):
df.drop_duplicates(['A', 'B'], take_last=True, inplace=True)
expected = orig.loc[[0, 5, 6, 7]]
result = df
tm.assert_frame_equal(result, expected)

# consider everything
orig2 = orig.loc[:, ['A', 'B', 'C']].copy()

Expand All @@ -1754,17 +1689,7 @@ def test_drop_duplicates_inplace(self):
result = df2
tm.assert_frame_equal(result, expected)

# deprecate take_last
df2 = orig2.copy()
with tm.assert_produces_warning(FutureWarning):
df2.drop_duplicates(take_last=True, inplace=True)
with tm.assert_produces_warning(FutureWarning):
expected = orig2.drop_duplicates(['A', 'B'], take_last=True)
result = df2
tm.assert_frame_equal(result, expected)

# Rounding

def test_round(self):
# GH 2665

Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -4025,8 +4025,6 @@ def test_nlargest(self):
3, 2, 1, 3, 3, 2
], index=MultiIndex.from_arrays([list('aaabbb'), [2, 3, 1, 6, 5, 7]]))
assert_series_equal(gb.nlargest(3, keep='last'), e)
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(gb.nlargest(3, take_last=True), e)

def test_nsmallest(self):
a = Series([1, 3, 5, 7, 2, 9, 0, 4, 6, 10])
Expand All @@ -4044,8 +4042,6 @@ def test_nsmallest(self):
0, 1, 1, 0, 1, 2
], index=MultiIndex.from_arrays([list('aaabbb'), [4, 1, 0, 9, 8, 7]]))
assert_series_equal(gb.nsmallest(3, keep='last'), e)
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(gb.nsmallest(3, take_last=True), e)

def test_transform_doesnt_clobber_ints(self):
# GH 7972
Expand Down
33 changes: 0 additions & 33 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,17 +917,6 @@ def test_drop_duplicates(self):
sc.drop_duplicates(keep='last', inplace=True)
assert_series_equal(sc, s[~expected])

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(s.duplicated(take_last=True), expected)
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(
s.drop_duplicates(take_last=True), s[~expected])
sc = s.copy()
with tm.assert_produces_warning(FutureWarning):
sc.drop_duplicates(take_last=True, inplace=True)
assert_series_equal(sc, s[~expected])

expected = Series([False, False, True, True])
assert_series_equal(s.duplicated(keep=False), expected)
assert_series_equal(s.drop_duplicates(keep=False), s[~expected])
Expand All @@ -951,17 +940,6 @@ def test_drop_duplicates(self):
sc.drop_duplicates(keep='last', inplace=True)
assert_series_equal(sc, s[~expected])

# deprecate take_last
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(s.duplicated(take_last=True), expected)
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(
s.drop_duplicates(take_last=True), s[~expected])
sc = s.copy()
with tm.assert_produces_warning(FutureWarning):
sc.drop_duplicates(take_last=True, inplace=True)
assert_series_equal(sc, s[~expected])

expected = Series([False, True, True, False, True, True, False])
assert_series_equal(s.duplicated(keep=False), expected)
assert_series_equal(s.drop_duplicates(keep=False), s[~expected])
Expand Down Expand Up @@ -1443,18 +1421,7 @@ def test_nsmallest_nlargest(self):
for s in s_list:

assert_series_equal(s.nsmallest(2), s.iloc[[2, 1]])

assert_series_equal(s.nsmallest(2, keep='last'), s.iloc[[2, 3]])
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(
s.nsmallest(2, take_last=True), s.iloc[[2, 3]])

assert_series_equal(s.nlargest(3), s.iloc[[4, 0, 1]])

assert_series_equal(s.nlargest(3, keep='last'), s.iloc[[4, 0, 3]])
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(
s.nlargest(3, take_last=True), s.iloc[[4, 0, 3]])

empty = s.iloc[0:0]
assert_series_equal(s.nsmallest(0), empty)
Expand Down
Loading

0 comments on commit 30372eb

Please sign in to comment.