wtclarke / pymapvbvd

Python port of mapVBVD
MIT License
44 stars 25 forks source link

int16 vs. uint8 missmatch #11

Closed JakobAsslaender closed 2 years ago

JakobAsslaender commented 2 years ago

Hi!

Thank a bunch for this toolbox, it's a great helper! Yet I have run into a bug: when I call the toolbox from within Python as intended, everything works fine. However, I would like to call it directly from Julia with the PyCall.jl package, and this case seems to be, for whatever reason, more sensitive to type inconsistencies. More precisely, when calling twixObj = mavbvd.mapVBVD(filename), I get the following error message:

UFuncTypeError(<ufunc 'bitwise_and'>, 'same_kind', dtype('int16'), dtype('uint8'), 2)
  File "~/.local/lib/python3.9/site-packages/mapvbvd/mapVBVD.py", line 360, in mapVBVD
    [mdh, mask] = evalMDH(mdh_blob, version)
  File "~/.local/lib/python3.9/site-packages/mapvbvd/mapVBVD.py", line 180, in evalMDH
    ulPCI_rx = set_bit(ulPCI_rx, 8, False)
  File "~/.local/lib/python3.9/site-packages/mapvbvd/mapVBVD.py", line 19, in set_bit
    v &= mask  # Clear the bit indicated by the mask (if x is False)

The issue is resolved by replacing the line 180 in mapVBVD.py: ulPCI_rx = set_bit(ulPCI_rx, 8, False) with ulPCI_rx = set_bit(np.int16(ulPCI_rx), 8, False)

I can create a pull request with this change if you want me to, but I was wondering if you would know of a cleaner solution. Thanks for looking into this!

-ja

wtclarke commented 2 years ago

Hi @JakobAsslaender ,

Thanks for reporting this. Another user just reported something similar. I think it might be a python version issue. It seems to work on 3.8 but not 3.9.

Please do make a pull request and we can test the solution out on a couple of versions of python.

BW,

Will

wtclarke commented 2 years ago

Hi @JakobAsslaender,

Thanks for making the PR. I've merged that in, and with a few other little bits, the fix should be in V0.4.5, which is up on Pypi and should follow within the next day or so on conda-forge. Tests are now run against python 3.6-3.10 using the Github CI actions framework.