Skip to content
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

Enforce scalar output for contour filter #2952

Merged
merged 2 commits into from
Jul 7, 2022
Merged

Conversation

akaszynski
Copy link
Member

Resolve #2901 by enforcing scalar output array name.

Bonus: Permits numpy.ndarray and sequences in scalars.

Thanks @adeak for pointing out the issues and producing a minimnum working example that replicates the error.

@github-actions github-actions bot added the bug Uh-oh! Something isn't working as expected. label Jul 7, 2022
@codecov
Copy link

codecov bot commented Jul 7, 2022

Codecov Report

Merging #2952 (cb24695) into main (21e4b3c) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2952      +/-   ##
==========================================
+ Coverage   94.28%   94.30%   +0.02%     
==========================================
  Files          76       76              
  Lines       16520    16527       +7     
==========================================
+ Hits        15576    15586      +10     
+ Misses        944      941       -3     

@akaszynski akaszynski enabled auto-merge (squash) July 7, 2022 18:14
@akaszynski akaszynski added this to the 0.35.0 milestone Jul 7, 2022
Copy link
Member

@adeak adeak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question about something that might hint at an unhandled failure mode, otherwise this LGTM.

Comment on lines +1608 to +1609
if scalars_name not in output.point_data:
if 'Unnamed_0' in output.point_data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what do we expect to be the situation when scalars_name not in output.point_data but 'Unnamed_0' not in output.point_data?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely that there are two unnamed arrays, in which case we don't handle this at all.

I figure that edge case to be unlikely enough unless there's another filter that outputs a null named array and we're not handling that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I understand correctly, is the problem that we wouldn't know which scalars array to grab? I assume there's no written guarantee that .get_array(0) is always the newest one (that's what I saw in 1 out of 1 quick tests). And I guess we'd still have to figure out the corresponding name.

OK, so as long as this is the best we can do it's all good. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be the best we can do. What you could do is check beforehand if any null arrays exist and then handle that, but this is quite an edge case.

If we can guarantee that the last null array added is the one we want, then we can just loop through the array names and pick the last "Unnamed_" array.

While we're on edge cases, here's another: what happens if someone names their array "Unnamed_0"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be the best we can do. What you could do is check beforehand if any null arrays exist and then handle that, but this is quite an edge case.

Yeah, I don't think it's worth the complexity.

While we're on edge cases, here's another: what happens if someone names their array "Unnamed_0"?

Ugh... all of these auto-array names should have leading double underscores, like the __rgba* one(s)...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. To be fixed.

@akaszynski akaszynski merged commit 47ddcd9 into main Jul 7, 2022
@akaszynski akaszynski deleted the fix/contour_scalrs branch July 7, 2022 19:54
Comment on lines 1580 to 1584
# NOTE: only point data is allowed? well cells works but seems buggy?
if field != FieldAssociation.POINT:
raise TypeError(
f'Contour filter only works on Point data. Array ({scalars}) is in the Cell data.'
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a remark: let's clean this up for v0.36 (i.e. preference input kwargs vs forced point scalars, we should refactor some of these checks too probably).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Are we already tracking this in an issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adeak
Copy link
Member

adeak commented Jul 7, 2022

Ah, auto-merge was on...

adeak added a commit to adeak/pyvista that referenced this pull request Jul 7, 2022
* upstream/main:
  Enforce scalar output for contour filter (pyvista#2952)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh-oh! Something isn't working as expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flying edges example broken after FFT PR
2 participants