diff --git a/RELEASE.rst b/RELEASE.rst index d26b599de05b1..a8769cd4bbc91 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -153,6 +153,7 @@ pandas 0.11.0 - util.testing.assert_frame_equal now checks the column and index names (GH2964_) - Constructors will now return a more informative ValueError on failures when invalid shapes are passed + - Methods return None when inplace=True (GH1893_) **Bug Fixes** @@ -251,6 +252,7 @@ pandas 0.11.0 .. _GH622: https://github.com/pydata/pandas/issues/622 .. _GH797: https://github.com/pydata/pandas/issues/797 +.. _GH1893: https://github.com/pydata/pandas/issues/1893 .. _GH1978: https://github.com/pydata/pandas/issues/1978 .. _GH2758: https://github.com/pydata/pandas/issues/2758 .. _GH2121: https://github.com/pydata/pandas/issues/2121 diff --git a/pandas/core/frame.py b/pandas/core/frame.py index bd9c609f6ef38..530ac3f539d3f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2708,16 +2708,9 @@ def set_index(self, keys, drop=True, append=False, inplace=False, frame.index = index - if inplace: - import warnings - warnings.warn("set_index with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - return self - else: + if not inplace: return frame - return frame if not inplace else None - def reset_index(self, level=None, drop=False, inplace=False, col_level=0, col_fill=''): """ @@ -2815,12 +2808,7 @@ def _maybe_cast(values): new_obj.insert(0, name, _maybe_cast(values)) new_obj.index = new_index - if inplace: - import warnings - warnings.warn("reset_index with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - return self - else: + if not inplace: return new_obj delevel = deprecate('delevel', reset_index) @@ -2988,10 +2976,6 @@ def drop_duplicates(self, cols=None, take_last=False, inplace=False): inds, = (-duplicated).nonzero() self._data = self._data.take(inds) self._clear_item_cache() - import warnings - warnings.warn("drop_duplicates with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - return self else: return self[-duplicated] @@ -3147,10 +3131,6 @@ def sort_index(self, axis=0, by=None, ascending=True, inplace=False): self._data = self._data.take(indexer) self._clear_item_cache() - import warnings - warnings.warn("sort/sort_index with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - return self else: return self.take(indexer, axis=axis, convert=False) @@ -3194,10 +3174,6 @@ def sortlevel(self, level=0, axis=0, ascending=True, inplace=False): self._data = self._data.take(indexer) self._clear_item_cache() - import warnings - warnings.warn("sortlevel with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - return self else: return self.take(indexer, axis=axis, convert=False) @@ -3328,10 +3304,6 @@ def fillna(self, value=None, method=None, axis=0, inplace=False, if inplace: self._data = new_data - import warnings - warnings.warn("fillna with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - return self else: return self._constructor(new_data) @@ -3380,10 +3352,6 @@ def replace(self, to_replace, value=None, method='pad', axis=0, self._consolidate_inplace() axis = self._get_axis_number(axis) - if inplace: - import warnings - warnings.warn("replace with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) if value is None: return self._interpolate(to_replace, method, axis, inplace, limit) @@ -3397,13 +3365,17 @@ def replace(self, to_replace, value=None, method='pad', axis=0, new_data = self._data for c, src in to_replace.iteritems(): if c in value and c in self: - new_data = new_data.replace(src, value[c], filter = [ c ], inplace=inplace) + new_data = new_data.replace(src, value[c], + filter=[ c ], + inplace=inplace) elif not isinstance(value, (list, np.ndarray)): new_data = self._data for k, src in to_replace.iteritems(): if k in self: - new_data = new_data.replace(src, value, filter = [ k ], inplace=inplace) + new_data = new_data.replace(src, value, + filter = [ k ], + inplace=inplace) else: raise ValueError('Fill value must be scalar or dict or Series') @@ -3430,7 +3402,9 @@ def replace(self, to_replace, value=None, method='pad', axis=0, new_data = self._data for k, v in value.iteritems(): if k in self: - new_data = new_data.replace(to_replace, v, filter = [ k ], inplace=inplace) + new_data = new_data.replace(to_replace, v, + filter=[ k ], + inplace=inplace) elif not isinstance(value, (list, np.ndarray)): # NA -> 0 new_data = self._data.replace(to_replace, value, @@ -3442,7 +3416,6 @@ def replace(self, to_replace, value=None, method='pad', axis=0, if inplace: self._data = new_data - return self else: return self._constructor(new_data) @@ -3525,12 +3498,7 @@ def rename(self, index=None, columns=None, copy=True, inplace=False): if columns is not None: result._rename_columns_inplace(columns_f) - if inplace: - import warnings - warnings.warn("rename with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - return self - else: + if not inplace: return result def _rename_index_inplace(self, mapper): diff --git a/pandas/core/series.py b/pandas/core/series.py index acfc875fa45a1..8e4d75af43fc9 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -122,7 +122,7 @@ def convert_to_array(values): # 2 datetimes or 2 timedeltas if (is_timedelta_lhs and is_timedelta_rhs) or (is_datetime_lhs and is_datetime_rhs): - + dtype = 'timedelta64[ns]' # we may have to convert to object unfortunately here @@ -601,7 +601,7 @@ def _is_mixed_type(self): def _slice(self, slobj, axis=0, raise_on_error=False): if raise_on_error: _check_slice_bounds(slobj, self.values) - + return self._constructor(self.values[slobj], index=self.index[slobj]) def __getitem__(self, key): @@ -1047,11 +1047,6 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False): self.index = new_index # set name if it was passed, otherwise, keep the previous name self.name = name or self.name - import warnings - warnings.warn("Series.reset_index with inplace=True will " - "return None from pandas 0.11 onward", - FutureWarning) - return self else: return Series(self.values.copy(), index=new_index, name=self.name) @@ -2615,13 +2610,8 @@ def fillna(self, value=None, method=None, inplace=False, ------- filled : Series """ - if inplace: - import warnings - warnings.warn("Series.fillna with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - if not self._can_hold_na: - return self.copy() if not inplace else self + return self.copy() if not inplace else None if value is not None: if method is not None: @@ -2647,9 +2637,7 @@ def fillna(self, value=None, method=None, inplace=False, else: result = Series(values, index=self.index, name=self.name) - if inplace: - return self - else: + if not inplace: return result def ffill(self, inplace=False, limit=None): @@ -2756,12 +2744,7 @@ def _rep_dict(rs, to_rep): # replace {[src] -> dest} raise ValueError('Unrecognized to_replace type %s' % type(to_replace)) - if inplace: - import warnings - warnings.warn("Series.replace with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - return self - else: + if not inplace: return result def isin(self, values): @@ -3110,12 +3093,7 @@ def rename(self, mapper, inplace=False): result = self if inplace else self.copy() result.index = Index([mapper_f(x) for x in self.index], name=self.index.name) - if inplace: - import warnings - warnings.warn("Series.rename with inplace=True will return None" - " from pandas 0.11 onward", FutureWarning) - return self - else: + if not inplace: return result @property diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index ced4b23b7e4fa..c17a39dd55d18 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -9427,7 +9427,7 @@ def test_strange_column_corruption_issue(self): self.assertTrue(first == second == 0) def test_inplace_return_self(self): - # re #1893, TODO: remove in 0.11 + # re #1893 data = DataFrame({'a': ['foo', 'bar', 'baz', 'qux'], 'b': [0, 0, 1, 1], @@ -9435,7 +9435,7 @@ def test_inplace_return_self(self): def _check_f(base, f): result = f(base) - self.assertTrue(result is base) + self.assertTrue(result is None) # -----DataFrame-----