-
Notifications
You must be signed in to change notification settings - Fork 90
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
Adding has_group and has_channel #314
Conversation
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.
Thanks for the contribution @looopTools, I've left a couple of comments for consideration
nptdms/tdms.py
Outdated
@@ -145,6 +145,17 @@ def groups(self): | |||
|
|||
return list(self._groups.values()) | |||
|
|||
def has_group(self, group_name): |
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 seems like a good use case for implementing the __contains__
method, so rather than using tdms_file.has_group('group_name')
you could use 'group_name' in tdms_file
, which I think would be more idiomatic Python.
In fact it looks like that second syntax already works due to TdmsFile
and TdmsGroup
implementing the __iter__
method, but it probably makes sense to provide a more efficient implementation.
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.
Thanks for the comment.
I agree I will see if I can get it working either today or Saturday :)
nptdms/tdms.py
Outdated
try: | ||
self._groups[group_name] | ||
except KeyError: | ||
return False | ||
return True |
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 can be simplified to return group_name in self._groups
I changed to using |
Thanks. Was it intentional to not implement |
I will implement that too :) |
Added Contains on TDMS File as well |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #314 +/- ##
=======================================
Coverage 96.89% 96.89%
=======================================
Files 19 19
Lines 2606 2610 +4
=======================================
+ Hits 2525 2529 +4
Misses 81 81
☔ View full report in Codecov by Sentry. |
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.
👍 thanks!
I am in a situation where I am not fully aware of what groups and channels are in which TDMS file.
Therefore we found it beneficial to have a function to ask if a
TdmsFile
has a group and ask if aTdmsGroup
has a channel.I though it could be beneficial to others as well