-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
updated regionprops_table test for iterable properties #5245
updated regionprops_table test for iterable properties #5245
Conversation
…ble_equal_to_original_update
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.
Excellent, thank you! With the breakdown introduced by separator="-"
, I'm not seeing any instance where i > 0
... Please correct me if I'm missing something!
It seems to me that all properties are covered by this main for loop:
for prop, dtype in COL_DTYPES.items():
for reg in regions:
rp = reg[prop]
if np.isscalar(rp) or \
prop in OBJECT_COLUMNS or \
dtype is np.object_:
assert_array_equal(rp, out_table[prop][0])
else:
shape = rp.shape if isinstance(rp, np.ndarray) else (len(rp),)
for ind in np.ndindex(shape):
modified_prop = "-".join(map(str, (prop,) + ind))
loc = ind if len(ind) > 1 else ind[0]
assert_equal(rp[loc], out_table[modified_prop][0])
Hi, thank you for your comment @mkcor ! Yeah you're right, reg=regions[0]
for prop, dtype in COL_DTYPES.items():
rp = reg[prop]
if np.isscalar(rp) or \
prop in OBJECT_COLUMNS or \
dtype is np.object_:
assert_array_equal(rp, out_table[prop][0])
else:
shape = rp.shape if isinstance(rp, np.ndarray) else (len(rp),)
for ind in np.ndindex(shape):
modified_prop = "-".join(map(str, (prop,) + ind))
loc = ind if len(ind) > 1 else ind[0]
assert_equal(rp[loc], out_table[modified_prop][0]) I'd be happy to hear your opinion on this! |
@yfukai ok, very well. This way your test is robust to the case where |
Wonderful, thanks! |
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.
Thank you @yfukai! The PR is really good. I just left two small suggestions 😉
if np.isscalar(rp) or \ | ||
prop in OBJECT_COLUMNS or \ | ||
dtype is np.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 np.isscalar(rp) or \ | |
prop in OBJECT_COLUMNS or \ | |
dtype is np.object_: | |
if np.isscalar(rp) or prop in OBJECT_COLUMNS: |
The dtype is np.object_
condition is not necessary.
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.
Oh thanks, I see! This is actually a copy from the logic in _regionprops.py
itself. I'll try to rewrite it in a bit more DRY way.
Co-authored-by: Riadh Fezzani <rfezzani@gmail.com>
Awesome, thank you again @yfukai! |
Oops! 😅 I saw the comment and the commit and made an assumption. 😬 Future PRs are absolutely welcome! I think this is already a major improvement anyway. =) |
Description
Associated with pull request #5239 and issue #5222 . I updated test
test_regionprops_table_equal_to_original
so that they compare not only non-iterable properties but also iterable ones ofregionprops
andregionprops_table
.Checklist
→ not applicable
./doc/examples
(new features only)→ not applicable
./benchmarks
, if your changes aren't covered by anexisting benchmark
→ not applicable
→ one modified here
→ checked with autopep8
For reviewers
later.
__init__.py
.doc/release/release_dev.rst
.