Repository navigation
dep & test: Replace deprecated functions and add tests for interface.py
#230
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
sbillinge
merged 6 commits into
diffpy:main
from
cadenmyers13:fix-structure-deprecations
Oct 15, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5fb7a89
chore: replace deprecated functions
cadenmyers13 fc89bd7
replace deprecated function in test
cadenmyers13 58c6781
fix deprecated functions in examples and add tests for interface
cadenmyers13 6513f14
fix file header
cadenmyers13 ed0fd62
trigger ci
cadenmyers13 b35b24d
doc: add short hand operators to docs
cadenmyers13 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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| **Added:** | ||
|
|
||
| * Document the ``*=``, ``%=``, ``+=``, ``|=``, and ``<<`` shorthand operators in the ``diffpy.srfit.interface`` API reference. | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * Use ``get_space_group``, ``position_formulas``, and ``u_formulas`` in place of the deprecated ``diffpy.structure`` functions ``GetSpaceGroup``, ``positionFormulas``, and ``UFormulas`` to silence deprecation warnings. | ||
| * Use ``add_constraint`` and ``add_soft_bounds`` in the ``*=`` and ``%=`` operators of ``RecipeOrganizerInterface`` so they no longer raise deprecation warnings for ``constrain`` and ``restrain``. | ||
| * Use ``pyobjcryst.crystal.create_crystal_from_cif``, ``scipy.optimize.leastsq``, and the ``particle_diameter`` argument of ``spherical_particle`` in the examples in place of deprecated or renamed APIs. | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
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
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/usr/bin/env python | ||
| ############################################################################## | ||
| # | ||
| # (c) 2026-present The DiffPy Team. All rights reserved. | ||
| # | ||
| # File coded by: Caden Myers | ||
| # | ||
| # See GitHub contributions for a more detailed list of contributors. | ||
| # https://github.com/diffpy/diffpy.srfit/graphs/contributors | ||
| # | ||
| # See LICENSE.rst for license information. | ||
| # | ||
| ############################################################################## | ||
| """Tests for the interface module.""" | ||
|
|
||
| from diffpy.srfit.fitbase import FitRecipe | ||
|
|
||
|
|
||
| def _make_recipe_with_variables(): | ||
| """Return a recipe with the variables p1 = 1 and p2 = 2.""" | ||
| recipe = FitRecipe("recipe") | ||
| p1 = recipe.create_new_variable("p1", 1) | ||
| p2 = recipe.create_new_variable("p2", 2) | ||
| return recipe, p1, p2 | ||
|
|
||
|
|
||
| # Test that "*=" constrains a Parameter to an equation. | ||
| # C1: p1 is constrained to "2*p2" with "*=", and p2 is then set to 3. | ||
| # Expected: p1 is constrained and its value is 6. | ||
| def test_constrain_operator(): | ||
| recipe, p1, p2 = _make_recipe_with_variables() | ||
| recipe *= "p1", "2*p2" | ||
| p2.set_value(3) | ||
| recipe._constraints[p1].update() | ||
| assert recipe.is_constrained(p1) | ||
| actual_p1_value = p1.get_value() | ||
| expected_p1_value = 6 | ||
| assert actual_p1_value == expected_p1_value | ||
|
|
||
|
|
||
| # Test that "%=" restrains an equation between soft bounds. | ||
| # C1: "p1+p2" is restrained between 0 and 10 with "%=", and p2 is then set | ||
| # to 10. | ||
| # Expected: The recipe has one restraint with a penalty of 1. | ||
| def test_restrain_operator(): | ||
| recipe, _, p2 = _make_recipe_with_variables() | ||
| recipe %= "p1+p2", 0, 10 | ||
| p2.set_value(10) | ||
| actual_number_of_restraints = len(recipe._restraints) | ||
| expected_number_of_restraints = 1 | ||
| assert actual_number_of_restraints == expected_number_of_restraints | ||
| (restraint,) = recipe._restraints | ||
| actual_penalty = restraint.penalty() | ||
| expected_penalty = 1 | ||
| assert actual_penalty == expected_penalty | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
tbh, i had no clue you could constrain/restrain parameters with
*=/%=. Kinda cool! Although not super intuitiveThere 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.
Classic Pavol. Is it in the docs, where the symbols are actually explained? If not, let's put it there.
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.
@sbillinge 😂 . Added it to the docs. built them and doubled checked it