romerogroup/pyprocar

Deprecated Numpy Type (np.float) + POSCAR parsing issue

wladerer opened this issue · 0 comments

I received the following error when using the kpath function

AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'cfloat'?

Using the current pyprocar installation through PyPI

System Details:
pyenv python 3.10.4
macOS Monterey

I installed the github repo to see if that would fix an existing issues, but it did not. I edited the scriptKpath.py file with the appropriate 64 bit float/int conventions recommended by numpy (np.float64 and np.int_ ). This did not immediately resolve the issue due to the way lines 68-70 handle parsing the POSCAR file.

    for j in range(len(positions_matrix)):
        positions_matrix0 = np.array(positions_matrix[j].split())[0:3]
        positions[j, :] = positions_matrix0.astype(np.float64)

In the first iteration of the for loop ( j = 0 ), the text that indicates the POSCAR coordinate convention 'Direct\n' is being picked up by the split() string function. This causes the script to fail when a string is being converted to a float object. I would suggest that you use a different mechanism to handle this issue.

I'm not sure what the current coding conventions are for pyprocar, but it might be beneficial to offload this process to a separate function or even a POSCAR object to handle data that is positionally dependent in a non-rigorous file format like POSCAR.

To make minimally invasive changes, I've just updated the index on the first line to avoid this issue

    for j in range(1, len(positions_matrix)):
        positions_matrix0 = np.array(positions_matrix[j].split())[1:3]
        positions[j, :] = positions_matrix0.astype(np.float64)

After doing so, the script runs with no issues. I can submit a PR