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

Unittest: RuntimeError: implement_array_function method already has a docstring #14012

Open
KreativeKrise opened this issue Jul 15, 2019 · 22 comments

Comments

@KreativeKrise
Copy link

My application uses the python package gensim, which requires numpy. I want to run some unit tests, but always get RuntimeError: implement_array_function method already has a docstring. It was tested on Windows 10 and Docker with python 3.7.4. The problem seems to exist since numpy 1.16.0. If I use numpy 1.15.4 it works without problems.

Reproducing code example:

import unittest
import numpy as np


class StartUpTest(unittest.TestCase):

    def setUp(self):
        return

    def testDefaultEndpoint(self):
        True

Error message:

Traceback (most recent call last):
  File "C:\Users\kreativekrise\AppData\Local\Programs\Python\Python37-32\lib\unittest\loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "C:\Users\kreativekrise\AppData\Local\Programs\Python\Python37-32\lib\unittest\loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "D:\work\projects\myapp\test\startup_test.py", line 2, in <module>
    import numpy as np
  File "C:\Users\kreativekrise\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Users\kreativekrise\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core\__init__.py", line 40, in <module>
    from . import multiarray
  File "C:\Users\kreativekrise\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\Users\kreativekrise\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core\overrides.py", line 46, in <module>
    """)
RuntimeError: implement_array_function method already has a docstring

Numpy/Python version information:

1.16.4 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)]

@The-Pied-Piper
Copy link

Is there any work around for this? This has made is impossible for us to run automated tests on our builds.

@emamulmursalin

This comment has been minimized.

@mattip
Copy link
Member

mattip commented Dec 8, 2019

Are you running tests with subinterpreters or somehow trying to re-initialize numpy in the same process after already importing it once (i.e. removing it from the sys.modules)? NumPy does not support that. Strange that it only began showing up in NumPy 1.16, are you sure that is the only change?

@aburrell
Copy link

aburrell commented Dec 8, 2019

Speaking for myself, I checked for re-initialization and that was not the problem. And yes, the numpy version increase was the only change in the system (no updates to the code at all) and tests that were previously passing on AppVeyor and Travis-CI started failing. Restricting the numpy version caused the tests to start passing again (as expected when the only change is the numpy version).

@rgommers
Copy link
Member

rgommers commented Dec 9, 2019

There's 22 upvotes on this, so very likely to be a real issue. It would be super helpful if someone provide a full reproducer. The issue description isn't enough, that does basically nothing and the environment isn't well-specified. Something like:

# On Windows 10 with Anaconda (other OS also fine, if using pip 
# please say how you installed Python)
conda create -n tmp python=3.7
conda activate tmp
conda install gensim
python some_code_to_run.py  # plus the actual code to put in this file

@fjsj
Copy link

fjsj commented Jan 2, 2020

@rgommers
Here's a full reproduction:

git clone https://github.com/dedupeio/dedupe.git
cd dedupe
pip install "numpy>=1.16"
pip install -r requirements.txt
cython src/*.pyx
python setup.py install

My env:

  • Python 3.8.1
  • macOS Mojave 10.14.6

@rgommers
Copy link
Member

rgommers commented Jan 3, 2020

@fjsj thanks. That passes for me. Is the python setup.py install failing for you, or are you running some code after that fails?

@fjsj
Copy link

fjsj commented Jan 3, 2020

@rgommers thanks for trying. Strange it passes. python setup.py install finishes with the output RuntimeError: implement_array_function method already has a docstring and exit code 1 for me.

Here are the full output of all steps: full-steps-with-output.txt

My env:

  • Python 3.8.1
  • macOS Mojave 10.14.6
  • fish version 2.7.1

Tried bash as well, got the same error.

@trevordavies095
Copy link

Any update on this?

@nicornk
Copy link

nicornk commented Apr 2, 2020

Is there any workaround available for this issue?

@jroitgrund
Copy link

jroitgrund commented Apr 16, 2020

@mattip i'm trying to debug an issue where importing numpy throws this error and would like to understand what is causing it. would you be able to explain the simplest way to reproduce this error?

e.g. simply doing

>>> import numpy
>>> import numpy

doesn't throw.

neither does your suggestion remove numpy from sys.modules:

import numpy
import sys

del sys.modules['numpy']
import numpy

Speaking for myself, I checked for re-initialization and that was not the problem

@aburrell how were you able to check for re-initialization?

@seberg
Copy link
Member

seberg commented Apr 16, 2020

@jroitgrund, I seem to recall that this would happened when there was somehow an install of NumPy with stray old files around. Can you try uninstalling numpy (as often as necessary) and then reinstalling it?
E.g. if you are using pip install numpy to install, run pip uninstall numpy multiple times just to be sure until pip complains.

EDIT: to be clear, I may recall this completely incorrectly, but it would still be good to know/check how you installed numpy.

@jroitgrund
Copy link

@seberg This is happening in a production environment where a lot of different things could be causing it, not on my local machine. I'm trying to understand specifically what causes the issue and find the smallest possible reproduction, so that I can debug my production environment.

@mattip
Copy link
Member

mattip commented Apr 16, 2020

fwiw, the Unittest: might be a clue. Some test frameworks use import tricks, maybe one of them is messing things up.

@jroitgrund
Copy link

jroitgrund commented Apr 16, 2020

Forgot to mention that doesn't repro it either for me.

$ cat test.py
import unittest
import numpy as np


class StartUpTest(unittest.TestCase):

    def setUp(self):
        return

    def testDefaultEndpoint(self):
        True
$ python -m unittest test.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
$ python --version
Python 3.7.6
$ python -c 'import numpy;print(numpy.version.version)'
1.18.2

EDIT: I guess more generally, if there's a known limitation of numpy and it's supposed to throw, does somebody know exactly what the limitation is? should numpy be defensive against that situation by asserting with a clear error message instead of the docstring error, which seems incidental?

@blakete
Copy link

blakete commented May 2, 2020

Has this not been solved?

@seberg
Copy link
Member

seberg commented May 2, 2020

@blakete are you building your own numpy, or any chance you had an old setup.py installed numpy, that (e.g. try uninstalling multiple times)? I am not sure this should happen unless you have modified anything. If you use a dev setup (git), ensure you delete all local changes with git clean -xdf before rebuilding.

@blakete
Copy link

blakete commented May 2, 2020

@seberg I have resolved the issue. Pycharm has a bug and is causing the issue. Apologies for the false alarm. It works perfectly via terminal. Cheers!

@schniewmatz
Copy link

@blakete Could you link the bug in Pycharm? I'm having a similar problem when running unittest in pycharm in debug mode.

@msarafzadeh
Copy link

@seberg I have resolved the issue. Pycharm has a bug and is causing the issue. Apologies for the false alarm. It works perfectly via terminal. Cheers!

is there a ticket to jetbrains?

@blakete
Copy link

blakete commented May 25, 2020

@schniewmatz I have not found the bug on any Pycharm channel but after updating it has resolved my issues. If that does not work, try invalidating / clearing Pycharm caches.

@msarafzadeh
Copy link

which version 2020.1 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests