-
Notifications
You must be signed in to change notification settings - Fork 189
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
py: ParticleSlice fixes #3367
py: ParticleSlice fixes #3367
Conversation
Codecov Report
@@ Coverage Diff @@
## python #3367 +/- ##
======================================
Coverage 86% 86%
======================================
Files 537 537
Lines 25283 25283
======================================
Hits 21806 21806
Misses 3477 3477 Continue to review full report at Codecov.
|
@KaiSzuttor, based on the offline discussion, I inserted a few comments which hopefully make things more clear |
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.
LGTM besides minor comments
self.id_selection = np.array(slice_, dtype=int) | ||
else: | ||
raise TypeError( | ||
"ParticleSlice must be initialized with an instance of slice or range, or with a list, tuple, or ndarray of ints, but got " + |
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.
we should probably use "some string {}".format(some_variable)
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
@@ -2026,8 +2048,7 @@ Set quat and scalar dipole moment (dipm) instead.") | |||
# Ids of the selected particles | |||
ids = [] | |||
# Did we get a function as argument? | |||
if len(args) == 1 and len(kwargs) == 0 and isinstance( | |||
args[0], types.FunctionType): | |||
if len(args) == 1 and len(kwargs) == 0 and callable(args[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.
remark: classes are callable
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.
Didn't find an other way to handle Cython oddities.
707f210
to
9ffdf6c
Compare
* Return correct elements if particle numbering is non-contigeous * Prevent slicing with negative indices due unclear outcome * Prevent slicing with True/False masks due to unclear outcome * Maintain order created by slicing, e.g. [9:0:-1] * Require that all particles exist when passing an explicit list of ids * Maintain order for explicit list of ids * More rigorous testing * Minor related fixes in other test cases
9ffdf6c
to
0a4cadd
Compare
self.id_selection = np.array(slice_, dtype=int) | ||
else: | ||
raise TypeError( | ||
"ParticleSlice must be initialized with an instance of slice or range, or with a list, tuple, or ndarray of ints, but got {} of type {}".foormat((str(slice_), str(type(slice_))))) |
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.
typo, is this raise 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.
the typo is .foormat
+ raise TypeError(
+ "ParticleSlice must be initialized with an instance of slice or range, or with a list, tuple, or ndarray of ints, but got {} of type {}".foormat((str(slice_), str(type(slice_)))))
typo, is this raise tested?
The spell checker in vim doesn't find the typo. Neither do I (but I'm not good at finding typos).
It's not clear which particular illegal type I should test here. The if is more narrow than the cases that would probably work (anything that is iterable and only contains int-likes). I saw no benefit in allowing more, though.
The more realistic errors such as lists containing non-int-likes are checked. [1, n_part/2]. There was at least one such regression in the testsuite which went undetected before this pr.
|
it seems like kodiak is missing an essential feature, namely updating PRs 😢 |
@KaiSzuttor @jngrad So, kodiak isn't up to the job? |
yes, see chdsbd/kodiak#104 |
Fixes #3363