Repository navigation
Conversation
Grid.__getitem__ rebuilt the selection with self.__class__(points, weights). AtomGrid, AngularGrid, LocalGrid and UniformGrid have other constructor arguments, so grid[0] or grid[1:4] on them raised TypeError.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Indexing most
Gridsubclasses fails, although indexing a plainGridworks:Cause:
Grid.__getitem__builds the selection withself.__class__(points, weights). That only works for classes whose constructor takes(points, weights).OneDGrid,MolGridandPeriodicGriddefine their own__getitem__. The classes above inherit the base one, and their constructors take other arguments.Fix:
Grid.__getitem__now returns a plainGrid, as its docstring already says ("Return a new Grid object with selected points"). A subset of an atomic, angular or uniform grid is no longer that kind of grid anyway, for example it has no full set of shells or no regular shape. The classes with their own__getitem__are unchanged.Tests
test_getitem_subclassesinsrc/grid/tests/test_grid.pyindexes aLocalGrid,AngularGrid,AtomGridandUniformGridwith0,np.int64(2)andslice(1, 4). It checks that the result is aGridwith the selected points and weights.masterand pass with this change.test_grid.py,test_periodicgrid.pyandtest_angular.pypass (159 passed).black -l 100 --checkonbasegrid.pypasses. Ontest_grid.py, black flags one blank line near the top that is already onmaster.