Skip to content

Conversation

@bobleesj
Copy link
Contributor

Closes#187 -

No docstrings made at the moment, but I will do in the next PR working on the issue #239

self_yarray = self.all_arrays[:, 0]
other_yarray = other.all_arrays[:, 0]
if len(self_yarray) != len(other_yarray):
if self_yarray.shape != other_yarray.shape:
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@sbillinge as suggested - using shape

Copy link
Contributor

Choose a reason for hiding this comment

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

the idea for using shape was to shorten code and make it more readable, so

 self_yarray = self.all_arrays[:, 0] other_yarray = other.all_arrays[:, 0] if len(self_yarray) != len(other_yarray): raise ValueError(y_grid_length_mismatch_emsg) 

is replaced by

 if shape(self.all_arrays) != shape(other.all_arrays): raise ValueError(y_grid_length_mismatch_emsg) 

@codecov
Copy link

codecovbot commented Dec 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (1ea8e9a) to head (21711fb).
Report is 9 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #293 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 8 8 Lines 446 483 +37 ========================================= + Hits 446 483 +37 
Files with missing linesCoverage Δ
tests/test_diffraction_objects.py100.00% <100.00%> (ø)


@pytest.mark.parametrize(
"starting_all_arrays, scalar_to_add, expected_all_arrays",
"operation, starting_yarray, scalar_value, expected_yarray",
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

operation b/w scalar and do

(np.array([[1.0, 6.28318531, 100.70777771, 1], [2.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]]),),
(np.array([[2.0, 6.28318531, 100.70777771, 1], [4.0, 3.14159265, 45.28748053, 2.0]]),),
# Test addition, subtraction, multiplication, and division of two DO objects
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

operation b/w do1 and do2



def test_operator_invalid_type(do_minimal_tth, invalid_add_type_error_msg):
# Add a string to a DiffractionObject, expect TypeError
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

invalid case - add string


@pytest.mark.parametrize("operation", ["add", "sub", "mul", "div"])
def test_operator_invalid_yarray_length(operation, do_minimal, do_minimal_tth, y_grid_size_mismatch_error_msg):
# Add two DO objects with different yarray lengths, expect ValueError
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

invalid case - add different lengths of yarray between 2 DOs

@bobleesj
Copy link
ContributorAuthor

@sbillinge ready for review!

@yucongalicechen
Copy link
Contributor

Do we want to add both metadata to the resulting diffraction object?
e.g. DO3 = DO1 / DO2, and DO3 contains metadata from both objects

Copy link
Contributor

@sbillingesbillinge left a comment

Choose a reason for hiding this comment

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

Looks good. I tried to shorten the all_arrays shape check part of the code before merging

self_yarray = self.all_arrays[:, 0]
other_yarray = other.all_arrays[:, 0]
if len(self_yarray) != len(other_yarray):
if self_yarray.shape != other_yarray.shape:
Copy link
Contributor

Choose a reason for hiding this comment

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

the idea for using shape was to shorten code and make it more readable, so

 self_yarray = self.all_arrays[:, 0] other_yarray = other.all_arrays[:, 0] if len(self_yarray) != len(other_yarray): raise ValueError(y_grid_length_mismatch_emsg) 

is replaced by

 if shape(self.all_arrays) != shape(other.all_arrays): raise ValueError(y_grid_length_mismatch_emsg) 

@sbillingesbillinge merged commit 90fd625 into diffpy:mainDec 30, 2024
5 checks passed
@bobleesjbobleesj deleted the op-mul-sub branch December 30, 2024 02:18
@bobleesj
Copy link
ContributorAuthor

@sbillinge ah yes. Great! Thanks

Sign up for freeto 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.

write tests for...

3 participants

@bobleesj@yucongalicechen@sbillinge