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

Issue with python example xrlexample5.py (numpy: int64 vs int) #218

Closed
delorytheape opened this issue Feb 9, 2023 · 2 comments
Closed

Comments

@delorytheape
Copy link

Hi,

I have just attempted to use xraylib with Python and have run into a problem with the example xrlexample5.py
The example throws an exception at line 67, while attempting to call xraylib.AtomicNumberToSymbol(Z[0]), where Z=np.array([26])
The output is

Traceback (most recent call last):

File "blah/Downloads/xraylib/example/xrlexample5.py", line 67, in <module>

symbol = xraylib.AtomicNumberToSymbol(Z[0])
File "blah/miniconda3/envs/py3/lib/python3.10/site-packages/xraylib.py", line 1037, in AtomicNumberToSymbol
return _xraylib.AtomicNumberToSymbol(Z)
TypeError: in method 'AtomicNumberToSymbol', argument 1 of type 'int'

ie. It looks like AtomicNumberToSymbol is expecting an int (but getting a numpy.int64).

To confirm this, I,

  • found a clean machine (Ubuntu 20.04),
  • installed xraylib using conda (> conda install -c conda-forge xraylib),
  • opened a python shell (python 3.9.15)
  • typed the following commands

>>> import numpy as np
>>> import xraylib
>>> xraylib.__version__
'4.1.2'
>>> xraylib.AtomicNumberToSymbol(26)
'Fe'
>>> type(26)
<class 'int'>
>>> xraylib.AtomicNumberToSymbol(np.array([26])[0])
Traceback (most recent call last):
File "", line 1 in
File "~/miniconda3/envs/py3/lib/python3.9/site-packages/xraylib.py", line 1037, in AtomicNumberToSymbol
return _xraylib.AtomicNumberToSymbol(Z)
TypeError: in method 'AtomicNumberToSymbol', argument 1 of type 'int'
`>>> type(np.array([26])[0])
<class 'numpy.int64'>

@tschoonj
Copy link
Owner

tschoonj commented Feb 9, 2023

Hi @delorytheape,

This bug was fixed in the 4.1.3 release. You may want to update your conda environment.

@delorytheape
Copy link
Author

Ok - thanks.

@tschoonj tschoonj closed this as completed Feb 9, 2023
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