-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TEST: dropna() doesn't fall into infinite loop #50751
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
Changes from 2 commits
56498f9
55e596a
6374d43
d11a3d8
fa8acb0
aed97cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2457,6 +2457,32 @@ def test_constructor_list_str_na(self, string_dtype): | |
expected = DataFrame({"A": ["1.0", "2.0", None]}, dtype=object) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_constructor_large_size_frame(self): | ||
class LargeFrame(DataFrame): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
for col in self.columns: | ||
if self.dtypes[col] == "O": | ||
self[col] = pd.to_numeric(self[col], errors="ignore") | ||
|
||
@property | ||
def _constructor(self): | ||
return type(self) | ||
|
||
def get_frame(N): | ||
return LargeFrame( | ||
data=np.vstack( | ||
[ | ||
np.where(np.random.rand(N) > 0.36, np.random.rand(N), np.nan) | ||
for _ in range(2) | ||
] | ||
).T | ||
) | ||
|
||
frame = get_frame(1000000) | ||
# check that dropna() doesn't fall into an infinite loop | ||
frame.dropna() | ||
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. Is there a way of breaking out of the infinite loop? This might cause weird ci Timeouts if we run into this bug again in the future 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. good point - in the notebook where I did git bisect I did class TimeoutError(Exception):
pass
def timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
def decorator(func):
def _handle_timeout(signum, frame):
raise TimeoutError(error_message)
@functools.wraps(func)
def wrapper(*args, **kwargs):
signal.signal(signal.SIGALRM, _handle_timeout)
signal.alarm(seconds)
try:
result = func(*args, **kwargs)
finally:
signal.alarm(0)
return result
return wrapper
return decorator
@timeout(5)
def long_running_function(n):
get_frame(n).dropna() , taken from https://stackoverflow.com/a/2282656/4451315 Perhaps this test could be rewritten to use that, with a comment indicating why (and linking to the stackoverflow answer) 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. Thank you, @MarcoGorelli. I will rewrite the test to avoid ci Timeout. 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. If the previous code was failing with an recursion error, I would recommend setting
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. I think this was just an infinite loop iirc, can check later 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. yeah it still hangs forever in 1.5 with 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. @mroeschke any objections to the current solution? When I tried 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. I am still a little weary about adding a test like this despite the timeout protection. Is it known what caused the infinite loop before? 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. sure, good point From https://www.kaggle.com/code/marcogorelli/pandas-regression-example?scriptVersionId=117662725, I'm seeing #49551 as the commit that fixed it, but I don't really see why that would be the case |
||
|
||
@pytest.mark.parametrize("copy", [False, True]) | ||
def test_dict_nocopy( | ||
self, | ||
|
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.
ah sorry, missed the GH reference - could you add a link to the issue #50708 as a comment please?