Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 19
Fix get_array_index returns int instead of list in DiffractionObject#283
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
| * <news item> | ||
| **Changed:** | ||
| * <news item> | ||
| **Deprecated:** | ||
| * <news item> | ||
| **Removed:** | ||
| * <news item> | ||
| **Fixed:** | ||
| * return type of `get_array_index` method in `DiffractionObject` to return integer instead of list | ||
| **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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -331,29 +331,29 @@ def uuid(self): | ||
| def uuid(self, _): | ||
| raise AttributeError(_setter_wmsg("uuid")) | ||
| def get_array_index(self, value, xtype=None): | ||
| def get_array_index(self, xtype, xvalue): | ||
| """Return the index of the closest value in the array associated with | ||
| the specified xtype. | ||
| the specified xtype and the value provided. | ||
sbillinge marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Parameters | ||
| ---------- | ||
| xtype str | ||
| the xtype used to access the array | ||
| value float | ||
| the target value to search for | ||
| xtype : str | ||
| The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}. | ||
| xvalue : float | ||
| The value of the xtype to find the closest index for. | ||
| Returns | ||
| ------- | ||
| list | ||
| The list containing the index of the closest value in the array. | ||
| int | ||
| The index of the closest value in the array associated with the specified xtype and the value provided. | ||
| """ | ||
| xtype = self._input_xtype | ||
| array = self.on_xtype(xtype)[0] | ||
| if len(array) == 0: | ||
| xarray = self.on_xtype(xtype)[0] | ||
| if len(xarray) == 0: | ||
| raise ValueError(f"The '{xtype}' array is empty. Please ensure it is initialized.") | ||
| i = (np.abs(array - value)).argmin() | ||
| return i | ||
| index = (np.abs(xarray - xvalue)).argmin() | ||
| return index | ||
| def _set_arrays(self, xarray, yarray, xtype): | ||
| self._all_arrays = np.empty(shape=(len(xarray), 4)) | ||
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 |
|---|---|---|
| @@ -364,7 +364,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs): | ||
| "xtype": "tth", | ||
| "value": 30.005, | ||
| }, | ||
| [0], | ||
| 0, | ||
sbillinge marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ), | ||
| ( # C2: Target value lies in the array, expect the (first) closest index | ||
| { | ||
| @@ -377,7 +377,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs): | ||
| "xtype": "tth", | ||
| "value": 45, | ||
| }, | ||
| [0], | ||
| 0, | ||
| ), | ||
| ( | ||
| { | ||
| @@ -390,7 +390,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs): | ||
| "xtype": "q", | ||
| "value": 0.25, | ||
| }, | ||
| [0], | ||
| 0, | ||
| ), | ||
| # C3: Target value out of the range, expect the closest index | ||
| ( # 1. Test with xtype of "q" | ||
| @@ -404,7 +404,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs): | ||
| "xtype": "q", | ||
| "value": 0.1, | ||
| }, | ||
| [0], | ||
| 0, | ||
| ), | ||
| ( # 2. Test with xtype of "tth" | ||
| { | ||
| @@ -417,20 +417,20 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs): | ||
| "xtype": "tth", | ||
| "value": 63, | ||
| }, | ||
| [1], | ||
| 1, | ||
| ), | ||
| ], | ||
| ) | ||
| def test_get_array_index(do_args, get_array_index_inputs, expected_index): | ||
| do = DiffractionObject(**do_args) | ||
| actual_index = do.get_array_index(get_array_index_inputs["value"], get_array_index_inputs["xtype"]) | ||
| actual_index = do.get_array_index(get_array_index_inputs["xtype"], get_array_index_inputs["value"]) | ||
| assert actual_index == expected_index | ||
| def test_get_array_index_bad(): | ||
| do = DiffractionObject(wavelength=2 * np.pi, xarray=np.array([]), yarray=np.array([]), xtype="tth") | ||
| with pytest.raises(ValueError, match=re.escape("The 'tth' array is empty. Please ensure it is initialized.")): | ||
| do.get_array_index(value=30) | ||
| do.get_array_index(xtype="tth", xvalue=30) | ||
| def test_dump(tmp_path, mocker): | ||
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.