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
Make MultiBlock meshes MutableSequence with some dict-like features for setting and getting. #3031
Conversation
This will be a breaking change that will be hard to deprecate. Should we start having a breaking change section in the PR description? It would be nice if we could somehow automatically label them as such and then organize the breaking changes in the release notes. |
That's a great idea. There are a few other breaking changes I'd like to incorporate this release as well. |
Codecov Report
@@ Coverage Diff @@
## main #3031 +/- ##
=======================================
Coverage 94.40% 94.40%
=======================================
Files 76 76
Lines 16643 16697 +54
=======================================
+ Hits 15712 15763 +51
- Misses 931 934 +3 |
I considered adding an |
This is now ready for review. There is one todo item that I need feedback on. I have implemented a tuple value assignment to replace the tuple inside the index based on the discussion in #1507. I have chosen the tuple to be |
I think keeping I'm mostly happy that we've eliminated this behavior
This should be so rare as to almost not be needed. I agree with this implementation and you can check this box off. |
Co-authored-by: Alex Kaszynski <akascap@gmail.com>
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.
One minor comment, but this is a vast improvement over the status quo, so I’d say this is good to go.
Since this is a moderately severe breaking change, should we explain the new, more logical design somewhere at e.g. https://dev.pyvista.org/api/core/composite.html? I'm not normally a |
Oh, and we'd definitely want |
This is definitely needs a critical re-review. The biggest changes were in formally inheriting from I took a stab at updating the documentation with the new data model. |
The documentation is partially failing due to the inherited methods from |
I chose to remove those mixin methods from the numpydoc check to get it to pass. The documentation for those methods will not be in the same style in PyVista, but consistent with the standard lib documentation. Assuming this passes the CI doc build too, it will be fully ready for review again. |
A |
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.
I've added two examples and made a few tiny changes in the docstrings for consistency, but otherwise LGTM.
Breaking Change
MultiBlock getting and setting behavior now acts more like a list with ability to use some dict-like features for convenience. Non-conforming usages were removed.
The following examples will no longer be possible:
multi[-1] = data
# appends datamulti = MultiBlock(); multi[5] = data
# sets length with an out of bound indexmulti[1, 'name'] = data
# sets key of data using second item of tuple index in setitemmulti[['name1', 'name2']]
# use lists of str instead of slicesmulti[[0, 1]]
# use lists of int instead of slicesmulti.next()
# get next blockThe following examples should be used instead:
multi[-1] = data
# access the last data entry.multi.append(data, 'name')
is the preferred method for appending and now accepts an optional name.multi['name'] = data
will also append if 'name' doesn't yet exist like a dict. It will overwrite the block 'name' if it exists.multi = MultiBlock(); multi.n_blocks = 6, multi[5] = data
# don't allow out of bounds indicesmulti[1] = data; multi.set_block_name(1, 'name')
# Use two lines to set name. Prefer to useappend
.multi[0:1] = [data1, data2]
# now slicing for setting is possiblenext(multi)
# get next blockmulti.replace(1, data)
# replace data, but preserve key nameOverview
This partially addresses #1507 and closes #1823. This PR proposes that MultiBlock meshes should act like lists, but we also allow dict like get/set behavior, and some additional feature sugar ontop.
Details
Additional behaviors like iter, next, etc. were not addressed in this PR.
TODO:
('name', data)
is preferred, decide what order should it be inget
, to more closely follow list-like, then dict-like behavior.