-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add DataSet.select_mtzdtype()
to subset DataSet
by MTZ column type
#150
Conversation
Codecov Report
@@ Coverage Diff @@
## main #150 +/- ##
==========================================
- Coverage 98.46% 98.46% -0.01%
==========================================
Files 43 43
Lines 1696 1690 -6
==========================================
- Hits 1670 1664 -6
Misses 26 26
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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 looks great. i made one small suggestion which might improve the test a tad.
Small bug: In [1]: mtz.head()
Out[1]:
BATCH I SIGI PARTIAL
H K L
19 -11 2 1424 2066.5464 32.449394 False
3 18 -1 328 2354.8054 29.814323 False
-17 21 17 576 20.76507 6.5568223 False
21 26 -7 70 23.690462 6.6323786 False
-9 17 11 798 459.89502 17.939333 False
In [2]: mtz.select_mtzdtype("B") # Select BatchDtype
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~/Documents/Hekstra_Lab/github/reciprocalspaceship/reciprocalspaceship/commandline/mtzdump.py in <module>
----> 1 mtz.select_mtzdtype("B") # Select BatchDtype
~/Documents/Hekstra_Lab/github/reciprocalspaceship/reciprocalspaceship/dataset.py in select_mtzdtype(self, dtype)
565 # One-letter code
566 if len(dtype) == 1:
--> 567 return self[[k for k in self if self[k].dtype.mtztype == dtype]]
568 else:
569 return self[[k for k in self if self[k].dtype.name == dtype]]
~/Documents/Hekstra_Lab/github/reciprocalspaceship/reciprocalspaceship/dataset.py in <listcomp>(.0)
565 # One-letter code
566 if len(dtype) == 1:
--> 567 return self[[k for k in self if self[k].dtype.mtztype == dtype]]
568 else:
569 return self[[k for k in self if self[k].dtype.name == dtype]]
AttributeError: 'numpy.dtype[bool_]' object has no attribute 'mtztype' This error occurs because only the custom # One-letter code
if len(dtype) == 1:
return self[[k for k in self if self[k].dtype.mtztype == dtype]] This can be fixed by first checking whether the mtztype attribute exists before checking its value: # One-letter code
if len(dtype) == 1:
return self[[k for k in self if hasattr(self[k].dtype, "mtztype") and self[k].dtype.mtztype == dtype]] |
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.
My only lingering question here is whether to explicitly test HKL
dtypes outside of the index. I'm going to approve it, because I think that call is up to you.
I updated the test to parametrize calls to Once CI passes, I'll merge this PR in. |
This PR adds a new function to
DataSet
,select_mtzdtype()
:This PR fixes #104, making it easier to subset a
DataSet
to columns of a desired MTZ column type.