Found the problem! When trying to reproduce the problem in a minimal code snippet, I noticed that when using only the first part of the module everything is OK. But when I add the rest of the code it fails again.
It turns out that I have, at some point, by mistake pasted an extra import numpy as np
deep down in the module. So, my mistake. But hard to find.
Thank you for your comments - those actually led to the finding of the issue.