Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36fd857
commit 6876c17
Showing
3 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -575,15 +575,27 @@ def where(self, cond, other=nan, inplace=False): | |
------- | ||
wh: Series | ||
""" | ||
if isinstance(cond, Series): | ||
cond = cond.reindex(self.index, fill_value=True) | ||
if not hasattr(cond, 'shape'): | ||
raise ValueError('where requires an ndarray like object for its ' | ||
'condition') | ||
if len(cond) != len(self): | ||
raise ValueError('condition must have same length as series') | ||
|
||
if inplace: | ||
ser = self if inplace else self.copy() | ||
if not isinstance(other, (list, tuple, np.ndarray)): | ||
self._set_with(~cond, other) | ||
return self | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
changhiskhan
Author
Contributor
|
||
|
||
return self._get_values(cond).reindex_like(self).fillna(other) | ||
if isinstance(other, Series): | ||
other = other.reindex(ser.index) | ||
if len(other) != len(ser): | ||
raise ValueError('Length of replacements must equal series length') | ||
|
||
np.putmask(ser, ~cond, other) | ||
|
||
return ser | ||
|
||
def mask(self, cond): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shouldn't this be ser? and not self, as inplace = False with a scalar (eg nan) will hit this and shouldn't modify the original series but the copy (which is what ser is here)