- Notifications
You must be signed in to change notification settings - Fork 21
Do not allow an empty instance of DiffractionObject - require xarraysyarraysxtype#228
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
bobleesj commented Dec 14, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
codecovbot commented Dec 14, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@## main #228 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 8 8 Lines 372 380 +8 ========================================= + Hits 372 380 +8
|
Uh oh!
There was an error while loading. Please reload this page.
| def input_data(self, xarray, yarray, xtype, wavelength, scat_quantity="", name="", metadata={}): | ||
| """ | ||
| Insert a new scattering quantity into the scattering object. |
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.
Improved docstrings, previous version:
f""" insert a new scattering quantity into the scattering object Parameters ---------- xarray array-like of floats the independent variable array yarray array-like of floats the dependent variable array xtype string the type of quantity for the independent variable from{*XQUANTITIES, } metadata, scat_quantity, name and wavelength are optional. They have the same meaning as in the constructor. Values will only be overwritten if non-empty values are passed. Returns ------- Nothing. Updates the object in place. """ 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.
If we make it private we may want to move the docstring to the constructor? Also, then change "insert a new scattering object blah blah, to instantiate a new scattering object or sthg.
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.
done
Uh oh!
There was an error while loading. Please reload this page.
sbillinge left a comment
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.
Please see inline. We may want to check it is ok for us to have things like empty string details instead of None that converts to empty string
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| def input_data(self, xarray, yarray, xtype, wavelength, scat_quantity="", name="", metadata={}): | ||
| """ | ||
| Insert a new scattering quantity into the scattering object. |
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.
If we make it private we may want to move the docstring to the constructor? Also, then change "insert a new scattering object blah blah, to instantiate a new scattering object or sthg.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| self.input_data(xarray, yarray, xtype) | ||
| self._input_xtype = xtype | ||
| self._set_xarrays(xarray, xtype) | ||
| self._all_arrays[:, 0] = yarray |
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.
It would be cleaner of this was moved into _set_arrays unless there was a reason not to do that because it is reused somewhere or something
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.
done
Uh oh!
There was an error while loading. Please reload this page.
tests/test_diffraction_objects.py Outdated
| "scat_quantity": "", | ||
| "wavelength": None, | ||
| "xtype": "", | ||
| "wavelength": 0.71, |
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.
Return wavelengths back to None or absent to test that behavior.
| tc_params = [ | ||
| ( | ||
| {}, |
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.
Where are these things now getting tested?
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.
pls see test_init_invalid_args below
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.
but I think these are valid aren't they?
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 I think these aren't valid since we DiffractionObject requires x, y, and xtype (current PR)
bobleesj commented Dec 14, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@sbillinge Before making PRs, when would be beneficial to have My understanding is that we usually want to pass typed variables so that typecasting can be minimal. Extra comment: I can see that having |
sbillinge commented Dec 14, 2024
I can't think of a case where we want none for xtype. I think we require this, right? For scat_quantity, the tradeoff is between making these easier to use (and therefore encouraging adoption) vs. making them stricter so we collect better metadata. I think leaning in the direction of adoption may be a good starting point for that (though if they are adopted, we may regret that later). That is the UC for a None default for scat_quantity: lazy users....
The issue is with setting mutable objects as defaults. In that case you should pass None and then you have logic like,
yes, in this case None is different from 0. We want None here. |
xarraysyarraysxtype| self.metadata = metadata | ||
| self.name = name | ||
| self._input_xtype = xtype | ||
| self._set_arrays(xarray, xtype, yarray) |
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.
as discussed - private func
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
bobleesj left a comment • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
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.
@sbillinge This is ready for review - pls see in-line comments..
bobleesj commented Dec 14, 2024
(Just added news) |
bobleesj left a comment
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 re-revisiting after resolving a conftest.py conflict. and ready for review.
sbillinge left a comment
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.
I reviewed this yesterday or so but it looks as if I forgot to submit the review.....sorry.
Uh oh!
There was an error while loading. Please reload this page.
| >>> x = np.array([0.12, 0.24, 0.31, 0.4]) # independent variable (e.g., q) | ||
| >>> y = np.array([10, 20, 40, 60]) # intensity values | ||
| >>> metadata ={ | ||
| ... "package_info":{"version": "3.6.0"} |
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.
this could only have been come up with by a programmer. Could we instead have an example of what we are after from materials scientists. Model some good behavior. Something like metadata ={'sample': "rock salt from the beach", "composition": "NaCl", "temperature": "300 K,", "experimenters": "Phill, Sally" }
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| return i | ||
| def _set_xarrays(self, xarray, xtype): | ||
| def _set_arrays(self, xarray, xtype, yarray): |
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.
maybe we should stay consistent...x, y, xtype order?
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.
done
Uh oh!
There was an error while loading. Please reload this page.
| tc_params = [ | ||
| ( | ||
| {}, |
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.
but I think these are valid aren't they?
Uh oh!
There was an error while loading. Please reload this page.
bobleesj commented Dec 16, 2024
@sbillinge ready for review! |
sbillinge commented Dec 16, 2024
There is a lot of good stuff on here and this is really getting wrestled into shape in my mind so I want to merge this (and will). There were two things left to do that I will mae issues for. Thanks for your work on this. It is really great! |
da32ae3 into diffpy:mainUh oh!
There was an error while loading. Please reload this page.

Closes#227