-
Notifications
You must be signed in to change notification settings - Fork 441
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
Do not set scalars as active when adding #3535
Conversation
These changes conflict with the |
I think there should be a comprehensive proposal here before moving forward. Otherwise we might want to change course again with another breaking change. This should be documented somewhere. I can think of two possibilities here for discussion, here I just focus on scalars:
I like either option 1 or option 2b. The following applies if option 2 or other implementation that sets active scalars. What about other array types? For example, what about when a (N, 3) array is saved? Should this be an active scalar when no other scalar exists or should it be active vector similarly, or both? What about Normals, Tensors, etc? We don't support all of these the same today, but it is worth thinking about to avoid further breaking changes like this. I think scalars, vectors, and Normals are the most common usages. I would vote for implementing this for the generic data, scalars, vectors, and tensors. Normals are a special data type. Do we support Tensors fully today? I propose the logic: if there is no active scalar/vector/tensor set and data is saved that is of suitable shape, set it as active. This would result in:
|
I genuinely prefer this as this follows "Explicit is better than implicit" where we minimize side effects as much as possible. There's of course a lack of convenience here, which is why we proposed making them active (and keeping them active) when using cube = pv.Cube()
cube['scalars'] = cube.points[:, 0] This makes it really convenient when plotting with This leaves us with either 2a or 2b
This seems like a compromise between "assign always" and "assign never". When a user sets data using That just leads us with 2a:
I prefer this behavior, the behavior proposed to keep (and really patch) in this PR. However, we need to consider @MatthewFlamm's comments regarding vector data:
Fully agree there. Right now we only address scalars. I recommend adding this in a follow-up PR and keeping this PR for the release since it's a bug fix of (I hope) agreed upon behavior. |
Codecov Report
@@ Coverage Diff @@
## main #3535 +/- ##
=======================================
Coverage 95.17% 95.17%
=======================================
Files 83 83
Lines 18571 18577 +6
=======================================
+ Hits 17675 17681 +6
Misses 896 896 |
Agreed with @akaszynski's summary + plan 👍 |
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.
Given the general consensus, I'm recommending approval for this. Summarizing:
- Agree with @banesullivan's approach of setting active scalars based on the "first" added if there are no active ones. It's a trade-off between usability and having an explicit API.
- We need a follow-up PR that does the same thing for vectors.
Ignoring the MNE CI failure. I'm sure @larsoner is aware and we passed before the jupyter warnings started causing the issue.
@MatthewFlamm, I know you're busy, but please let me know if you're fine with this and we can move forward with the follow-up PR. |
I'm okay with this PR. Im not convinced that we should greedily activate generated data as much as possible however and this can wait for a future conversation. For example, it doesn't make sense to me to make the data resulting from I suppose I'm proposing that we should set active X when the data being generated is the primary expected outcome of an operation. Here X is whatever type is relevant, e.g. scalars or normals or... If the data generated is ancillary, then do not make it active. For example, in some cases the original ID of a point/cell may be stored during a geometrical operation. Does it makes sense to make these active scalars? |
I think we're all on the same page. This PR can be the first step to improving active scalars (and vectors/tensors to follow). IMO, I think this PR is ready to merge as is given @akaszynski's plan above |
Let's merge and open an issue with "the plan". |
Overview
Helps address #1897 and should solve #3486
Details
These changes prevent a scenario where a mesh may already have active scalars and adding a new array automatically gets set as active. #1897 and #3486 outline several places where this behavior has unintended consequences
The behavior is as follows when adding a new scalar array (point or cell data):
Example
main