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

Geometry methods don't accept atoms=[] #370

Closed
pfebrer opened this issue Aug 27, 2021 · 1 comment
Closed

Geometry methods don't accept atoms=[] #370

pfebrer opened this issue Aug 27, 2021 · 1 comment

Comments

@pfebrer
Copy link
Contributor

pfebrer commented Aug 27, 2021

When Geometry sanitizes atoms=[] it returns an empty numpy array of dtype float64. That causes problems because, even though it doesn't contain any indices, arrays don't accept it as an indexer, as it is not of dtype int or bool.

Reproducable code

import sisl
sisl.geom.graphene().sub(atoms=[])
IndexError                                Traceback (most recent call last)
<ipython-input-20-053c248b033e> in <module>
----> 1 sisl.geom.graphene().sub(atoms=[])

~/webDevelopement/sislGUI/sisl/sisl/geometry.py in sub(self, atoms, cell)
   1701         atoms = self.sc2uc(atoms)
   1702         if cell is None:
-> 1703             return self.__class__(self.xyz[atoms, :],
   1704                                   atoms=self.atoms.sub(atoms), sc=self.sc.copy())
   1705         return self.__class__(self.xyz[atoms, :],

IndexError: arrays used as indices must be of integer (or boolean) type

The same error is raised by:

sisl.geom.graphene().sub(atoms=np.array([], dtype=float))

(which makes more sense, but still I don't know if this should raise an exception)
but not by:

sisl.geom.graphene().sub(atoms=np.array([], dtype=int))
@zerothi
Copy link
Owner

zerothi commented Aug 27, 2021

Thanks!

pfebrer pushed a commit to pfebrer/sisl that referenced this issue Sep 8, 2021
When passing a zero length index, asarray will
convert to float (it does not know what dtype it is).
This ensures casting to ints.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants