-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Can't store callables using __setitem__ #13516
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
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -4419,54 +4419,10 @@ def _align_series(self, other, join='outer', axis=None, level=None, | |
right = right.fillna(fill_value, method=method, limit=limit) | ||
return left.__finalize__(self), right.__finalize__(other) | ||
|
||
_shared_docs['where'] = (""" | ||
Return an object of same shape as self and whose corresponding | ||
entries are from self where cond is %(cond)s and otherwise are from | ||
other. | ||
|
||
Parameters | ||
---------- | ||
cond : boolean %(klass)s, array or callable | ||
If cond is callable, it is computed on the %(klass)s and | ||
should return boolean %(klass)s or array. | ||
The callable must not change input %(klass)s | ||
(though pandas doesn't check it). | ||
|
||
.. versionadded:: 0.18.1 | ||
|
||
A callable can be used as cond. | ||
|
||
other : scalar, %(klass)s, or callable | ||
If other is callable, it is computed on the %(klass)s and | ||
should return scalar or %(klass)s. | ||
The callable must not change input %(klass)s | ||
(though pandas doesn't check it). | ||
|
||
.. versionadded:: 0.18.1 | ||
|
||
A callable can be used as other. | ||
|
||
inplace : boolean, default False | ||
Whether to perform the operation in place on the data | ||
axis : alignment axis if needed, default None | ||
level : alignment level if needed, default None | ||
try_cast : boolean, default False | ||
try to cast the result back to the input type (if possible), | ||
raise_on_error : boolean, default True | ||
Whether to raise on invalid data types (e.g. trying to where on | ||
strings) | ||
|
||
Returns | ||
------- | ||
wh : same type as caller | ||
""") | ||
|
||
@Appender(_shared_docs['where'] % dict(_shared_doc_kwargs, cond="True")) | ||
def where(self, cond, other=np.nan, inplace=False, axis=None, level=None, | ||
def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a docstring to this one explaining it's purpose? |
||
try_cast=False, raise_on_error=True): | ||
|
||
cond = com._apply_if_callable(cond, self) | ||
other = com._apply_if_callable(other, self) | ||
|
||
if isinstance(cond, NDFrame): | ||
cond, _ = cond.align(self, join='right', broadcast_axis=1) | ||
|
@@ -4622,6 +4578,55 @@ def where(self, cond, other=np.nan, inplace=False, axis=None, level=None, | |
|
||
return self._constructor(new_data).__finalize__(self) | ||
|
||
_shared_docs['where'] = (""" | ||
Return an object of same shape as self and whose corresponding | ||
entries are from self where cond is %(cond)s and otherwise are from | ||
other. | ||
|
||
Parameters | ||
---------- | ||
cond : boolean %(klass)s, array or callable | ||
If cond is callable, it is computed on the %(klass)s and | ||
should return boolean %(klass)s or array. | ||
The callable must not change input %(klass)s | ||
(though pandas doesn't check it). | ||
|
||
.. versionadded:: 0.18.1 | ||
|
||
A callable can be used as cond. | ||
|
||
other : scalar, %(klass)s, or callable | ||
If other is callable, it is computed on the %(klass)s and | ||
should return scalar or %(klass)s. | ||
The callable must not change input %(klass)s | ||
(though pandas doesn't check it). | ||
|
||
.. versionadded:: 0.18.1 | ||
|
||
A callable can be used as other. | ||
|
||
inplace : boolean, default False | ||
Whether to perform the operation in place on the data | ||
axis : alignment axis if needed, default None | ||
level : alignment level if needed, default None | ||
try_cast : boolean, default False | ||
try to cast the result back to the input type (if possible), | ||
raise_on_error : boolean, default True | ||
Whether to raise on invalid data types (e.g. trying to where on | ||
strings) | ||
|
||
Returns | ||
------- | ||
wh : same type as caller | ||
""") | ||
|
||
@Appender(_shared_docs['where'] % dict(_shared_doc_kwargs, cond="True")) | ||
def where(self, cond, other=np.nan, inplace=False, axis=None, level=None, | ||
try_cast=False, raise_on_error=True): | ||
|
||
other = com._apply_if_callable(other, self) | ||
return self._where(cond, other, inplace, axis, level, try_cast, raise_on_error) | ||
|
||
@Appender(_shared_docs['where'] % dict(_shared_doc_kwargs, cond="False")) | ||
def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, | ||
try_cast=False, raise_on_error=True): | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually maybe put this in API changes to make it a bit more prominent.