-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: maximum recursion error when replacing empty lists #22083
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
+39
−3
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a3f688a
minor docstring
minggli c97b2ee
prevent infinite recursion error
minggli 941fccb
negative mask if no match or na
minggli 389ebcd
revert generic
minggli 5573658
revert missing
minggli e7dad7e
add test case for series.replace
minggli 309216c
boolean mask guaranteed if None
minggli 402d983
add test case for frame
minggli 3604031
update series test
minggli 001c3a0
use different error to avoid recursion
minggli 91100f7
modify tests to expect intended error
minggli 8271576
change error type and avoid infinite loop
minggli 167a3b7
revert test_boolean
minggli f657ae3
revert type of error
minggli c8f4f72
only retry if the block is not ObjectBlock
minggli d3c3236
add comment
minggli 899724f
Merge branch 'master' into bugfix/replace_recursion
minggli 0c2bae3
Merge remote-tracking branch 'upstream/master' into bugfix/replace_re…
minggli a8020b9
add whatsnew
minggli 201adf6
minor change in whatsnew
minggli c4a4a8b
add empty list
minggli 2bbd097
minor refactor
minggli 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -777,10 +777,9 @@ def copy(self, deep=True, mgr=None): | |
|
||
def replace(self, to_replace, value, inplace=False, filter=None, | ||
regex=False, convert=True, mgr=None): | ||
""" replace the to_replace value with value, possible to create new | ||
"""replace the to_replace value with value, possible to create new | ||
blocks here this is just a call to putmask. regex is not used here. | ||
It is used in ObjectBlocks. It is here for API | ||
compatibility. | ||
It is used in ObjectBlocks. It is here for API compatibility. | ||
""" | ||
|
||
inplace = validate_bool_kwarg(inplace, 'inplace') | ||
|
@@ -802,14 +801,19 @@ def replace(self, to_replace, value, inplace=False, filter=None, | |
copy=not inplace) for b in blocks] | ||
return blocks | ||
except (TypeError, ValueError): | ||
# try again with a compatible block | ||
block = self.astype(object) | ||
return block.replace(to_replace=original_to_replace, | ||
value=value, | ||
inplace=inplace, | ||
filter=filter, | ||
regex=regex, | ||
convert=convert) | ||
# GH 22083, TypeError or ValueError occurred within error handling | ||
# causes infinite loop. Cast and retry only if not objectblock. | ||
if self.dtype == 'object': | ||
raise | ||
else: | ||
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. don't need this else here |
||
# try again with a compatible block | ||
block = self.astype(object) | ||
return block.replace(to_replace=original_to_replace, | ||
value=value, | ||
inplace=inplace, | ||
filter=filter, | ||
regex=regex, | ||
convert=convert) | ||
|
||
def _replace_single(self, *args, **kwargs): | ||
""" no-op on a non-ObjectBlock """ | ||
|
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.
can you use is_object_dtype