-
Notifications
You must be signed in to change notification settings - Fork 21
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
fix: compare values and shape of xarray
values before applying operations between 2 DiffractionObjects
#299
Conversation
@@ -255,7 +256,9 @@ def _check_operation_compatibility(self, other): | |||
raise TypeError(invalid_add_type_emsg) | |||
if isinstance(other, DiffractionObject): | |||
if self.all_arrays.shape != other.all_arrays.shape: |
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.
We need to first check the shape. Without this condition, the error message is ValueError: operands could not be broadcast together with shapes (0,3) (2,3) error message
instead of getting the expected error message in x_values_not_equal_emsg
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #299 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 500 511 +11
=========================================
+ Hits 500 511 +11
|
[ | ||
# Test addition, subtraction, multiplication, and division of two DO objects | ||
( # Test addition of two DO objects, expect combined yarray values | ||
"add", | ||
np.array([[2.0, 0.51763809, 30.0, 12.13818192], [4.0, 1.0, 60.0, 6.28318531]]), | ||
np.array([[2.0, 6.28318531, 100.70777771, 1], [4.0, 3.14159265, 45.28748053, 2.0]]), | ||
np.array([[2.0, 0.51763809, 30.0, 12.13818192], [4.0, 1.0, 60.0, 6.28318531]]), |
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.
add two DOs with identical xarrays, expect valid without error.
): | ||
# Add two DO objects with different xarray values but equal in shape, expect ValueError | ||
do_1 = do_minimal_tth | ||
do_2 = do_minimal_d |
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.
do1 and do2 have differnet xarray values, expect invalid.
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 ready for review
cc' @yucongalicechen
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.
nicely done there.
Closes #298 -