-
Couldn't load subscription status.
- Fork 52
completed: containers, simresult, and test updates #527
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
completed: containers, simresult, and test updates #527
Conversation
|
Thank you for opening this PR. Each PR into dev requires a code review. For the code review, look at the following:
|
5/5/2023
5/9/2023
5/10/2023
5/10/2023
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
Codecov Report
@@ Coverage Diff @@
## dev #527 +/- ##
==========================================
- Coverage 84.65% 84.48% -0.17%
==========================================
Files 34 34
Lines 2515 2585 +70
==========================================
+ Hits 2129 2184 +55
- Misses 386 401 +15
|
|
Benchmarking Results [Update]
To:
|
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.
A few cosmetic comments, now I'm going to look into sim_result and container
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.
Great first step towards data frames simresult and container. I'll review the tests next.
src/prog_models/sim_result.py
Outdated
| Getter -- creating multi row pd.DataFrame from data list of dict | ||
| Return: pd.DataFrame, of all the data and times |
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.
| Getter -- creating multi row pd.DataFrame from data list of dict | |
| Return: pd.DataFrame, of all the data and times | |
| pd.DataFrame: A pandas DataFrame representing the SimResult data |
Updating documentation to describe it as a property. Describing it as a getter might make people expect to call it as a function.
src/prog_models/sim_result.py
Outdated
| self._frame = None | ||
|
|
||
| def time(self, index : int) -> float: | ||
| def get_time(self, index: int) -> float: |
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.
What's the reason for this change? This will change the interface.
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 was so confusing when looking at self.time(x) and self.time[x] side by side that I felt like that change would help with readability. It's also following the python naming convention
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 disagree with your statement about this following python naming conventions though. I think this is more java naming conventions, python prefers to use the name rather than get_name.
From https://python-consistency.readthedocs.io/en/latest/conventions.html:
"* Do not use get_... Prefer to use the name without the get_ prefix."
That said, I see what you mean about the confusion of self.times[x] and self.time(x). And with times being accessible, this function is also redundant. Why don't we instead move towards making users access times[x] only? We can keep time for one release (per ProgPy policy) with a deprecation warning telling users to use .times[x] instead. What do you think?
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.
What I meant was that the function getting an object variable such as time shouldn't have the same name, yes I instinctively renamed it get_time, it should have been gettime. That kind of naming convention. I realized later that this would be deprecated. I agree with the warning.
src/prog_models/sim_result.py
Outdated
| if all(item in self.frame.columns.to_list() for item in keys) is True: | ||
| with_keys_numpy = self.frame.drop(['time'], axis=1)[keys].to_numpy(dtype=np.float64) | ||
| return with_keys_numpy |
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 all(item in self.frame.columns.to_list() for item in keys) is True: | |
| with_keys_numpy = self.frame.drop(['time'], axis=1)[keys].to_numpy(dtype=np.float64) | |
| return with_keys_numpy | |
| for key in keys: | |
| if key not in self.frame: | |
| raise KeyError(f'Every key in keys must be present in SimResult. Missing {key}') | |
| return self.frame[keys].to_numpy(dtype=np.float64) |
Rewrote to raise exception
Co-authored-by: Christopher Teubert <christopher.a.teubert@nasa.gov>
edited based on Chris Teubert suggestion
Co-authored-by: Christopher Teubert <christopher.a.teubert@nasa.gov>
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.
Great initial step towards pandas data frame simresult and *containers. Great work!
A few small recommendations.
Thanks,
Chris
| import sys | ||
| import unittest | ||
|
|
||
| from numpy import float64 |
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.
Can we use np.float64 instead of importing it separately
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.
yes, I think that was added by pycharm
| c1.matrix[1][0] = -2.0 | ||
| c1.update({'b': -2.0}) | ||
| self.assertTrue(np.all(c1.matrix == np.array([[-1.], [-2.]]))) | ||
| self.assertEqual(c1['b'], -2.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.
| c1.matrix[1][0] = -2.0 | |
| c1.update({'b': -2.0}) | |
| self.assertTrue(np.all(c1.matrix == np.array([[-1.], [-2.]]))) | |
| self.assertEqual(c1['b'], -2.0) | |
| c1.matrix[1][0] = -2.0 | |
| self.assertTrue(np.all(c1.matrix == np.array([[-1.], [-2.]]))) | |
| self.assertEqual(c1['b'], -2.0) | |
| # Test update function | |
| c1.update({'b': -2.0}) | |
| self.assertTrue(np.all(c1.matrix == np.array([[-1.], [-2.]]))) | |
| self.assertEqual(c1['b'], -2.0) |
The way it's currently done doesn't test .matrix setting. Instead it tests that either matrix or update works.
| class TestSimResult(unittest.TestCase): | ||
| def setUp(self): | ||
| # set stdout (so it wont print) | ||
| """def setUp(self): |
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 uncomment the setup/tear down
Co-authored-by: Christopher Teubert <christopher.a.teubert@nasa.gov>
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
07cd465 to
b3ad9b0
Compare
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
Simresult suggestions
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
|
Benchmarking Results [Update]
To:
|
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.
Change of warning is fine.
| import sys | ||
| import unittest | ||
|
|
||
| from numpy import float64 |
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.
yes, I think that was added by pycharm
src/prog_models/sim_result.py
Outdated
| self._frame = None | ||
|
|
||
| def time(self, index : int) -> float: | ||
| def get_time(self, index: int) -> float: |
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.
What I meant was that the function getting an object variable such as time shouldn't have the same name, yes I instinctively renamed it get_time, it should have been gettime. That kind of naming convention. I realized later that this would be deprecated. I agree with the warning.
src/prog_models/sim_result.py
Outdated
| DeprecationWarning, stacklevel=2) | ||
| return super().__getitem__(item) | ||
|
|
||
| def iloc(self, item): |
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 has been done
5/5/2023