INCF / csa

The Python implementation of the Connection-Set Algebra
GNU General Public License v3.0
13 stars 17 forks source link

RuntimeError: generator raised StopIteration #16

Closed espenhgn closed 4 years ago

espenhgn commented 5 years ago

Hi @mdjurfeldt.
I'm experiencing an issue with Python 3.7 with the csa library installed from PyPI. Couldn't get the current master branch of the repo to install properly (python setup.py install used to work fine - now there's a lack of a csa/__init__.py file for instance):

In [1]: import numpy as np

In [2]: np.__version__
Out[2]: '1.15.4'

In [3]: import csa

In [4]: csa.__version__
Out[4]: '0.1.8'

In [5]: import sys

In [6]: sys.version
Out[6]: '3.7.2 (default, Dec 30 2018, 08:55:50) \n[Clang 10.0.0 (clang-1000.11.45.5)]'

In [7]: np.array([x for x in csa.cross(range(100), range(100)) * (csa.random(0.1) - csa.oneToOne)])
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
~/Library/Python/3.7/lib/python/site-packages/csa/connset.py in iterator(self, low0, high0, low1, high1, state)
    462                 yield (i1, j1)
--> 463                 (i1, j1) = next (iter1)
    464                 continue

StopIteration: 

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
<ipython-input-7-dfb0eb2b28d7> in <module>()
----> 1 np.array([x for x in csa.cross(range(100), range(100)) * (csa.random(0.1) - csa.oneToOne)])

<ipython-input-7-dfb0eb2b28d7> in <listcomp>(.0)
----> 1 np.array([x for x in csa.cross(range(100), range(100)) * (csa.random(0.1) - csa.oneToOne)])

~/Library/Python/3.7/lib/python/site-packages/csa/connset.py in simpleIterator(self, state)
    724                 for e in self.subMask.iterator (i0[0], i0[1] + 1,
    725                                                 i1[0], i1[1] + 1,
--> 726                                                 state):
    727                     yield e
    728 

RuntimeError: generator raised StopIteration

The code used to run fine on Python 2.7, 3.4-3.6. Don't know why the change to 3.7 would change anything.

bjuergens commented 4 years ago

this looks like an error introduced by python3.7

Q: “RuntimeError: generator raised StopIteration"

A: To judge from the file paths, it looks like you're running Python 3.7. If so, you're getting caught by new-in-3.7 behavior

https://stackoverflow.com/a/51701040/5132456

Christian-B commented 4 years ago

We get the same error in python 3.7 only. 3.6 works.

This is caused by the change describe in: https://docs.python.org/3/whatsnew/3.7.html and specifically https://www.python.org/dev/peps/pep-0479

An iterator that depends on other iterators must specifically catch and deal with the inner StopIteration

mdjurfeldt commented 4 years ago

Should be fixed in commit a4edc138

Closing