Skip to content

Commit

Permalink
in core/frame.py
Browse files Browse the repository at this point in the history
removed mask method
made other optional kw parm in where
changed __setitem__ to use where (rather than mask)
  • Loading branch information
jreback committed Nov 13, 2012
1 parent 030bc66 commit 8034116
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
19 changes: 2 additions & 17 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ def __getitem__(self, key):
return self._getitem_multilevel(key)
elif isinstance(key, DataFrame):
if key.values.dtype == bool:
return self.mask(key)
return self.where(key)
else:
raise ValueError('Cannot index using non-boolean DataFrame')
else:
Expand Down Expand Up @@ -4867,7 +4867,7 @@ def combineMult(self, other):
"""
return self.mul(other, fill_value=1.)

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

def mask(self, cond):
"""
Returns copy of self whose values are replaced with nan if the
corresponding entry in cond is False
Parameters
----------
cond: boolean DataFrame or array
Returns
-------
wh: DataFrame
"""
return self.where(cond, NA)

_EMPTY_SERIES = Series([])


Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def test_getitem_boolean(self):
self.assertRaises(ValueError, self.tsframe.__getitem__, self.tsframe)

# test df[df >0] works

bif = self.tsframe[self.tsframe > 0]
bifw = DataFrame(np.where(self.tsframe>0,self.tsframe,np.nan),index=self.tsframe.index,columns=self.tsframe.columns)
self.assert_(isinstance(bif,DataFrame))
Expand Down Expand Up @@ -5215,8 +5214,6 @@ def test_where(self):
for k, v in rs.iteritems():
assert_series_equal(v, np.where(cond[k], df[k], other5))

assert_frame_equal(rs, df.mask(cond))

err1 = (df + 1).values[0:2, :]
self.assertRaises(ValueError, df.where, cond, err1)

Expand Down

0 comments on commit 8034116

Please sign in to comment.