brisvag / napari-molecule-reader

BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

Reader does not work with numpy 1.22.x #6

Closed Czaki closed 2 years ago

Czaki commented 2 years ago

When try use this plugin with te newest numpy version (1.22.1) it fail to load file with error:

~/.pyenv/versions/3.8.3/envs/partseg3.8/lib/python3.8/site-packages/napari_molecule_reader/bonds.py in guess_bonds(atoms, fudge)
     52     # same model
     53     model = atoms['model'].to_numpy()
---> 54     same_model = np.equal.reduce(model[pairs], axis=1)
     55 
     56     # alternate loc indicator

TypeError: No loop matching the specified signature and casting was found for ufunc equal

Tested on stable and repository version. Downgrade to 1.21.5 solve this problem.

brisvag commented 2 years ago

I'm confused about this... The previous calls of np.equal.reduce are passing?

Also, I cannot reproduce with my files. What PDB are you using? Is there something odd with model info?

Czaki commented 2 years ago

files from pdb database for example: 3mht. I will try to provide more detailed information after 2PM. I have a seminar now.

brisvag commented 2 years ago

My bad, I had messed up a bit my environment; I can reproduce with other files as well!

brisvag commented 2 years ago

This sounds like a bug in numpy honestly. This works on 1.21.5:

In [13]: np.equal.reduce([0, 1])
Out[13]: False

In [14]: np.equal.reduce([0, 0])
Out[14]: True

But fails on 1.22. It seems that np.equal.reduce now only works with object dtype. That can't be right, right?

Czaki commented 2 years ago

But fails on 1.22. It seems that np.equal.reduce now only works with object dtype. That can't be right, right?

it works also with a boolean numpy array. Maybe it is a bug in NumPy, but I do not find a proper issue so I'm not sure.

There are two options. Try to work around this or mark this extension as incompatible with this version of NumPy.

EDIT. And your testing environment on GitHub actions is failing because of this error.

brisvag commented 2 years ago

I filed a bug, let's see what they say. numpy/numpy#20929

brisvag commented 2 years ago

Turns out I was just using reduce wrong, and this numpy update made it clear. Fixed in v0.1.2, just published!