Skip to content

API: Raise/Warn SettingWithCopyError in more cases #5939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ API Changes

- ``Series.sort`` will raise a ``ValueError`` (rather than a ``TypeError``) on sorting an
object that is a view of another (:issue:`5856`, :issue:`5853`)

.. _release.bug_fixes-0.13.1:
- Raise/Warn ``SettingWithCopyError`` (according to the option ``chained_assignment`` in more cases,
when detecting chained assignment, related (:issue:`5938`)
- DataFrame.head(0) returns self instead of empty frame (:issue:`5846`)

Experimental Features
~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -72,7 +73,8 @@ Improvements to existing features
- df.info() view now display dtype info per column (:issue: `5682`)
- perf improvements in DataFrame ``count/dropna`` for ``axis=1``
- Series.str.contains now has a `regex=False` keyword which can be faster for plain (non-regex) string patterns. (:issue: `5879`)
- DataFrame.head(0) returns self instead of empty frame (:issue:`5846`)

.. _release.bug_fixes-0.13.1:

Bug Fixes
~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,7 @@ def _box_col_values(self, values, items):
name=items, fastpath=True)

def __setitem__(self, key, value):

# see if we can slice the rows
indexer = _convert_to_index_sliceable(self, key)
if indexer is not None:
Expand All @@ -1880,6 +1881,7 @@ def _setitem_array(self, key, value):
(len(key), len(self.index)))
key = _check_bool_indexer(self.index, key)
indexer = key.nonzero()[0]
self._check_setitem_copy()
self.ix._setitem_with_indexer(indexer, value)
else:
if isinstance(value, DataFrame):
Expand All @@ -1889,6 +1891,7 @@ def _setitem_array(self, key, value):
self[k1] = value[k2]
else:
indexer = self.ix._convert_to_indexer(key, axis=1)
self._check_setitem_copy()
self.ix._setitem_with_indexer((slice(None), indexer), value)

def _setitem_frame(self, key, value):
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,14 @@ def f():
assert_series_equal(s,df.iloc[:,0].order())
assert_series_equal(s,df[0].order())

# operating on a copy
df = pd.DataFrame({'a': list(range(4)), 'b': list('ab..'), 'c': ['a', 'b', np.nan, 'd']})
mask = pd.isnull(df.c)

def f():
df[['c']][mask] = df[['b']][mask]
self.assertRaises(com.SettingWithCopyError, f)

pd.set_option('chained_assignment','warn')

def test_float64index_slicing_bug(self):
Expand Down