Skip to content
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

Merged
merged 3 commits into from
Dec 3, 2024
Merged

Conversation

patricktnast
Copy link
Contributor

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 in formatting.py, then went ahead and just added copy=True to all series / dataframe instantiations in formatting.py just to be safe.

Testing

Added tests first, verified they failed, then verified they now pass.

@@ -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)
Copy link
Contributor

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)
Copy link
Contributor

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):
Copy link
Contributor

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?

@patricktnast patricktnast merged commit 41b31f4 into main Dec 3, 2024
6 checks passed
@patricktnast patricktnast deleted the pnast/refactor/MIC-5595-mutable-state branch December 3, 2024 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants