Skip to content

Commit b904029

Browse files
committed
API: restore inplace=TRue returns self, add FutureWarnings. re #1893
1 parent cccbe7c commit b904029

File tree

10 files changed

+198
-70
lines changed

10 files changed

+198
-70
lines changed

RELEASE.rst

+10-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ pandas 0.10.1
3131

3232
- Add data inferface to World Bank WDI pandas.io.wb (#2592)
3333

34+
**API Changes**
35+
36+
- Restored inplace=True behavior returning self (same object) with
37+
deprecation warning until 0.11 (GH1893_)
38+
- ``HDFStore``
39+
- refactored HFDStore to deal with non-table stores as objects, will allow future enhancements
40+
- removed keyword ``compression`` from ``put`` (replaced by keyword
41+
``complib`` to be consistent across library)
42+
- warn `PerformanceWarning` if you are attempting to store types that will be pickled by PyTables
43+
3444
**Improvements to existing features**
3545

3646
- ``HDFStore``
@@ -111,15 +121,6 @@ pandas 0.10.1
111121
- Fix buggy interaction with usecols argument in read_csv when there is an
112122
implicit first index column (GH2654_)
113123

114-
**API Changes**
115-
116-
- ``HDFStore``
117-
118-
- refactored HFDStore to deal with non-table stores as objects, will allow future enhancements
119-
- removed keyword ``compression`` from ``put`` (replaced by keyword
120-
``complib`` to be consistent across library)
121-
- warn `PerformanceWarning` if you are attempting to store types that will be pickled by PyTables
122-
123124
.. _GH512: https://github.com/pydata/pandas/issues/512
124125
.. _GH1277: https://github.com/pydata/pandas/issues/1277
125126
.. _GH2070: https://github.com/pydata/pandas/issues/2070

pandas/core/frame.py

+46-4
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,15 @@ def set_index(self, keys, drop=True, append=False, inplace=False,
27552755
index._cleanup()
27562756

27572757
frame.index = index
2758+
2759+
if inplace:
2760+
import warnings
2761+
warnings.warn("set_index with inplace=True will return None"
2762+
" from pandas 0.11 onward", FutureWarning)
2763+
return self
2764+
else:
2765+
return frame
2766+
27582767
return frame if not inplace else None
27592768

27602769
def reset_index(self, level=None, drop=False, inplace=False, col_level=0,
@@ -2854,7 +2863,13 @@ def _maybe_cast(values):
28542863
new_obj.insert(0, name, _maybe_cast(values))
28552864

28562865
new_obj.index = new_index
2857-
return new_obj if not inplace else None
2866+
if inplace:
2867+
import warnings
2868+
warnings.warn("reset_index with inplace=True will return None"
2869+
" from pandas 0.11 onward", FutureWarning)
2870+
return self
2871+
else:
2872+
return new_obj
28582873

28592874
delevel = deprecate('delevel', reset_index)
28602875

@@ -3014,6 +3029,10 @@ def drop_duplicates(self, cols=None, take_last=False, inplace=False):
30143029
inds, = (-duplicated).nonzero()
30153030
self._data = self._data.take(inds)
30163031
self._clear_item_cache()
3032+
import warnings
3033+
warnings.warn("drop_duplicates with inplace=True will return None"
3034+
" from pandas 0.11 onward", FutureWarning)
3035+
return self
30173036
else:
30183037
return self[-duplicated]
30193038

@@ -3168,6 +3187,10 @@ def sort_index(self, axis=0, by=None, ascending=True, inplace=False):
31683187
self._data = self._data.take(indexer)
31693188

31703189
self._clear_item_cache()
3190+
import warnings
3191+
warnings.warn("sort/sort_index with inplace=True will return None"
3192+
" from pandas 0.11 onward", FutureWarning)
3193+
return self
31713194
else:
31723195
return self.take(indexer, axis=axis)
31733196

@@ -3210,6 +3233,10 @@ def sortlevel(self, level=0, axis=0, ascending=True, inplace=False):
32103233
self._data = self._data.take(indexer)
32113234

32123235
self._clear_item_cache()
3236+
import warnings
3237+
warnings.warn("sortlevel with inplace=True will return None"
3238+
" from pandas 0.11 onward", FutureWarning)
3239+
return self
32133240
else:
32143241
return self.take(indexer, axis=axis)
32153242

@@ -3337,6 +3364,10 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
33373364

33383365
if inplace:
33393366
self._data = new_data
3367+
import warnings
3368+
warnings.warn("fillna with inplace=True will return None"
3369+
" from pandas 0.11 onward", FutureWarning)
3370+
return self
33403371
else:
33413372
return self._constructor(new_data)
33423373

@@ -3384,6 +3415,11 @@ def replace(self, to_replace, value=None, method='pad', axis=0,
33843415
"""
33853416
self._consolidate_inplace()
33863417

3418+
if inplace:
3419+
import warnings
3420+
warnings.warn("replace with inplace=True will return None"
3421+
" from pandas 0.11 onward", FutureWarning)
3422+
33873423
if value is None:
33883424
return self._interpolate(to_replace, method, axis, inplace, limit)
33893425
else:
@@ -3416,7 +3452,7 @@ def replace(self, to_replace, value=None, method='pad', axis=0,
34163452

34173453
if inplace:
34183454
self._data = new_data
3419-
return None
3455+
return self
34203456
else:
34213457
return self._constructor(new_data)
34223458
else:
@@ -3427,7 +3463,7 @@ def replace(self, to_replace, value=None, method='pad', axis=0,
34273463
inplace=inplace)
34283464
if inplace:
34293465
self._data = new_data
3430-
return None
3466+
return self
34313467
else:
34323468
return self._constructor(new_data)
34333469

@@ -3534,7 +3570,13 @@ def rename(self, index=None, columns=None, copy=True, inplace=False):
35343570
if columns is not None:
35353571
result._rename_columns_inplace(columns_f)
35363572

3537-
return result if not inplace else None
3573+
if inplace:
3574+
import warnings
3575+
warnings.warn("rename with inplace=True will return None"
3576+
" from pandas 0.11 onward", FutureWarning)
3577+
return self
3578+
else:
3579+
return result
35383580

35393581
def _rename_index_inplace(self, mapper):
35403582
self._data = self._data.rename_axis(mapper, axis=1)

pandas/core/series.py

+29-5
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,11 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):
937937
self.index = new_index
938938
# set name if it was passed, otherwise, keep the previous name
939939
self.name = name or self.name
940-
return
940+
import warnings
941+
warnings.warn("Series.reset_index with inplace=True will "
942+
"return None from pandas 0.11 onward",
943+
FutureWarning)
944+
return self
941945
else:
942946
return Series(self.values.copy(), index=new_index,
943947
name=self.name)
@@ -2469,8 +2473,13 @@ def fillna(self, value=None, method=None, inplace=False,
24692473
-------
24702474
filled : Series
24712475
"""
2476+
if inplace:
2477+
import warnings
2478+
warnings.warn("Series.fillna with inplace=True will return None"
2479+
" from pandas 0.11 onward", FutureWarning)
2480+
24722481
if not self._can_hold_na:
2473-
return self.copy() if not inplace else None
2482+
return self.copy() if not inplace else self
24742483

24752484
if value is not None:
24762485
if method is not None:
@@ -2496,7 +2505,10 @@ def fillna(self, value=None, method=None, inplace=False,
24962505
else:
24972506
result = Series(values, index=self.index, name=self.name)
24982507

2499-
return result if not inplace else None
2508+
if inplace:
2509+
return self
2510+
else:
2511+
return result
25002512

25012513
def ffill(self, inplace=False, limit=None):
25022514
return self.fillna(method='ffill', inplace=inplace, limit=limit)
@@ -2596,7 +2608,13 @@ def _rep_dict(rs, to_rep): # replace {[src] -> dest}
25962608
raise ValueError('Unrecognized to_replace type %s' %
25972609
type(to_replace))
25982610

2599-
return result if not inplace else None
2611+
if inplace:
2612+
import warnings
2613+
warnings.warn("Series.replace with inplace=True will return None"
2614+
" from pandas 0.11 onward", FutureWarning)
2615+
return self
2616+
else:
2617+
return result
26002618

26012619
def isin(self, values):
26022620
"""
@@ -2944,7 +2962,13 @@ def rename(self, mapper, inplace=False):
29442962
result = self if inplace else self.copy()
29452963
result.index = [mapper_f(x) for x in self.index]
29462964

2947-
return result if not inplace else None
2965+
if inplace:
2966+
import warnings
2967+
warnings.warn("Series.rename with inplace=True will return None"
2968+
" from pandas 0.11 onward", FutureWarning)
2969+
return self
2970+
else:
2971+
return result
29482972

29492973
@property
29502974
def weekday(self):

pandas/io/tests/test_parsers.py

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def read_table(self, *args, **kwargs):
5454
raise NotImplementedError
5555

5656
def setUp(self):
57+
import warnings
58+
warnings.filterwarnings(action='ignore', category=FutureWarning)
59+
5760
self.dirpath = curpath()
5861
self.csv1 = os.path.join(self.dirpath, 'test1.csv')
5962
self.csv2 = os.path.join(self.dirpath, 'test2.csv')

pandas/io/tests/test_pytables.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class TestHDFStore(unittest.TestCase):
3232
scratchpath = '__scratch__.h5'
3333

3434
def setUp(self):
35+
warnings.filterwarnings(action='ignore', category=FutureWarning)
36+
3537
self.path = '__%s__.h5' % tm.rands(10)
3638
self.store = HDFStore(self.path)
3739

pandas/sparse/tests/test_sparse.py

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
from test_array import assert_sp_array_equal
3939

40+
import warnings
41+
warnings.filterwarnings(action='ignore', category=FutureWarning)
42+
4043

4144
def _test_data1():
4245
# nan-based

0 commit comments

Comments
 (0)