-
Notifications
You must be signed in to change notification settings - Fork 3
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
Remove Mutable State Bug #72
Conversation
@@ -191,9 +191,9 @@ def format_call_data(call_data, parameters): | |||
"If providing call_data as a series it must " | |||
"be indexed consistently with the parameter data." | |||
) | |||
call_data = pd.Series(call_data, index=parameters.index) | |||
call_data = pd.Series(call_data, index=parameters.index, copy=True) |
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.
TIL about copy.
@pytest.mark.parametrize("distribution", distributions) | ||
def test_cdf(test_data, distribution): | ||
mean, sd, test_q = test_data | ||
test_distribution = distribution(mean=mean, sd=sd) | ||
x_min, x_max = test_distribution.parameters.x_min, test_distribution.parameters.x_max | ||
|
||
# TODO MIC-5595: Find and fix places where inputs are mutated in-place | ||
test_x = test_distribution.ppf(test_q.copy()) | ||
test_x = test_distribution.ppf(test_q) |
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 we delete the #TODO right above this line then?
@pytest.mark.parametrize("distribution", distributions) | ||
@pytest.mark.parametrize("mean, sd", parameters) | ||
@pytest.mark.parametrize("test_q", test_qs) | ||
def test_no_state_mutations(mean, sd, test_q, distribution): |
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.
And this test failed prior to your fix?
Remove Mutable State Bug
Description
Changes and notes
Risk Distributions had a bug where you could mutate the state of an underlying pandas series, so it would hide issues when you used that same input series as a check against some output. I added copy=True to the
format_call_data
method informatting.py
, then went ahead and just added copy=True to all series / dataframe instantiations informatting.py
just to be safe.Testing
Added tests first, verified they failed, then verified they now pass.