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

get_points_in_sphere() has inconsistent return types #3794

Closed
fxcoudert opened this issue Apr 30, 2024 · 1 comment · Fixed by #3797
Closed

get_points_in_sphere() has inconsistent return types #3794

fxcoudert opened this issue Apr 30, 2024 · 1 comment · Fixed by #3797
Labels

Comments

@fxcoudert
Copy link

Python version

3.11.5

Pymatgen version

2024.4.13

Operating system version

No response

Current behavior

When get_points_in_sphere() is called with zip_results=False, it returns a tuple of numpy arrays:

            return frac_coords, distances, indices, images

However, if it found no point in the requested radius, then… the return type changes:

                return [] if zip_results else [()] * 4

So now it's returning four empty tuples. It is very surprising to the use, because using numpy functions of those will raise a type error. For example, I was doing things like np.any(distances < 1.0): that would work perfectly as expected with an empty numpy array, but will crash with an empty tuple.

Expected Behavior

I don't see what is gained by returning () instead of np.array([]) and it would be less surprising to users (I just spent half an hour understanding this weird behavior).

Minimal example

No response

Relevant files to reproduce this bug

No response

@janosh
Copy link
Member

janosh commented May 1, 2024

@fxcoudert thanks for reporting! will be fixed by #3797

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants