Skip to content

Commit 8034116

Browse files
committed
in core/frame.py
removed mask method made other optional kw parm in where changed __setitem__ to use where (rather than mask)
1 parent 030bc66 commit 8034116

File tree

2 files changed

+2
-20
lines changed

2 files changed

+2
-20
lines changed

pandas/core/frame.py

Lines changed: 2 additions & 17 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ def __getitem__(self, key):
1776
return self._getitem_multilevel(key)
1776
return self._getitem_multilevel(key)
1777
elif isinstance(key, DataFrame):
1777
elif isinstance(key, DataFrame):
1778
if key.values.dtype == bool:
1778
if key.values.dtype == bool:
1779-
return self.mask(key)
1779+
return self.where(key)
1780
else:
1780
else:
1781
raise ValueError('Cannot index using non-boolean DataFrame')
1781
raise ValueError('Cannot index using non-boolean DataFrame')
1782
else:
1782
else:
@@ -4867,7 +4867,7 @@ def combineMult(self, other):
4867
"""
4867
"""
4868
return self.mul(other, fill_value=1.)
4868
return self.mul(other, fill_value=1.)
4869

4869

4870-
def where(self, cond, other, inplace=False):
4870+
def where(self, cond, other=NA, inplace=False):
4871
"""
4871
"""
4872
Return a DataFrame with the same shape as self and whose corresponding
4872
Return a DataFrame with the same shape as self and whose corresponding
4873
entries are from self where cond is True and otherwise are from other.
4873
entries are from self where cond is True and otherwise are from other.
@@ -4901,21 +4901,6 @@ def where(self, cond, other, inplace=False):
4901
rs = np.where(cond, self, other)
4901
rs = np.where(cond, self, other)
4902
return self._constructor(rs, self.index, self.columns)
4902
return self._constructor(rs, self.index, self.columns)
4903

4903

4904-
def mask(self, cond):
4905-
"""
4906-
Returns copy of self whose values are replaced with nan if the
4907-
corresponding entry in cond is False
4908-
4909-
Parameters
4910-
----------
4911-
cond: boolean DataFrame or array
4912-
4913-
Returns
4914-
-------
4915-
wh: DataFrame
4916-
"""
4917-
return self.where(cond, NA)
4918-
4919
_EMPTY_SERIES = Series([])
4904
_EMPTY_SERIES = Series([])
4920

4905

4921

4906

pandas/tests/test_frame.py

Lines changed: 0 additions & 3 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -142,7 +142,6 @@ def test_getitem_boolean(self):
142
self.assertRaises(ValueError, self.tsframe.__getitem__, self.tsframe)
142
self.assertRaises(ValueError, self.tsframe.__getitem__, self.tsframe)
143

143

144
# test df[df >0] works
144
# test df[df >0] works
145-
146
bif = self.tsframe[self.tsframe > 0]
145
bif = self.tsframe[self.tsframe > 0]
147
bifw = DataFrame(np.where(self.tsframe>0,self.tsframe,np.nan),index=self.tsframe.index,columns=self.tsframe.columns)
146
bifw = DataFrame(np.where(self.tsframe>0,self.tsframe,np.nan),index=self.tsframe.index,columns=self.tsframe.columns)
148
self.assert_(isinstance(bif,DataFrame))
147
self.assert_(isinstance(bif,DataFrame))
@@ -5215,8 +5214,6 @@ def test_where(self):
5215
for k, v in rs.iteritems():
5214
for k, v in rs.iteritems():
5216
assert_series_equal(v, np.where(cond[k], df[k], other5))
5215
assert_series_equal(v, np.where(cond[k], df[k], other5))
5217

5216

5218-
assert_frame_equal(rs, df.mask(cond))
5219-
5220
err1 = (df + 1).values[0:2, :]
5217
err1 = (df + 1).values[0:2, :]
5221
self.assertRaises(ValueError, df.where, cond, err1)
5218
self.assertRaises(ValueError, df.where, cond, err1)
5222

5219

0 commit comments

Comments
 (0)