Skip to content

Conversation

davidrsch
Copy link
Owner

This pull request fixes a bug in remove_keras_spec that caused the function to delete multiple models if their names shared a common prefix.

The fix replaces the broad regex matching with a more specific approach. It now generates a list of exact object names to remove by combining the model name with a set of predefined suffixes (_args, _encoding, _fit, etc.). This ensures that only the objects directly related to the specified model are removed.

Changes

  • Added a new test case to tests/testthat/test_e2e_spec_removal.R to verify that the function no longer removes models with similar names.
  • Modified remove_keras_spec in R/remove_keras_spec.R to use a more specific method for identifying objects to delete.

This change makes the remove_keras_spec function safer and more predictable.

expect_true(exists(model_name_2, inherits = FALSE))
expect_no_error(parsnip:::check_model_doesnt_exist(model_name))
expect_error(parsnip:::check_model_doesnt_exist(model_name_2))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change


# cleanup
remove_keras_spec(model_name_2)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
})
})

Copy link

codecov bot commented Sep 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@davidrsch davidrsch merged commit 3571233 into main Sep 11, 2025
10 of 12 checks passed
@davidrsch davidrsch deleted the remove_keras_spec_issue branch September 11, 2025 11:10
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.

Bug report: remove_keras_spec deletes multiple models if their names share a common prefix
1 participant