pyDOE icon indicating copy to clipboard operation
pyDOE copied to clipboard

python3 error

Open andreacortis opened this issue 6 years ago • 5 comments

(doe) LC25423:Envs corti938$ ipython Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33) Type 'copyright', 'credits' or 'license' for more information IPython 7.1.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from pyDOE import *

In [2]: import pyDOE

In [3]: pyDOE.version
Out[3]: '0.3.8'

In [4]: fullfact([2, 3])

TypeError Traceback (most recent call last) in ----> 1 fullfact([2, 3])

~/my_codes/Envs/doe/lib/python3.6/site-packages/pyDOE/doe_factorial.py in fullfact(levels) 76 for j in range(levels[i]): 77 lvl += [j]level_repeat ---> 78 rng = lvlrange_repeat 79 level_repeat *= levels[i] 80 H[:, i] = rng

TypeError: can't multiply sequence by non-int of type 'numpy.float64'

andreacortis avatar Oct 30 '18 14:10 andreacortis

I have the same issue

Can we get the version of numpy and scipy that were used for testing the package?

Also what python 3 version?

StefanNa avatar Nov 27 '18 15:11 StefanNa

Hopefully this isn't dead...but heres my versions

numpy: 1.15.1 python: 3.5 scipy: 1.2.0

bgoodman44 avatar Jan 11 '19 15:01 bgoodman44

I too have the same issue (using python 3.7.2, pyDOE 0.3.8). This led me to do some digging.

The error stems from the fact that Python 3.x updated the behavior of division. Dividing two ints now produces a float.

PEP 238: https://www.python.org/dev/peps/pep-0238/ Stack Overflow: https://stackoverflow.com/q/1282945

# python 3.7.2
>>> 1/2
0.5

If you want to continue using floor division in python 3.x then you use the // operator.

# python 3.7.2
>>> 1//2
0

The nice thing is that the // operator also works in at least python 2.7 (I haven't tested any other 2.x version).

It'll work if you change doe_factorial.py line 74 to use the // operator.

    range_repeat = np.prod(levels)
    for i in range(n):
        range_repeat //= levels[i]    # updated from range_repeat /= levels[i]

It looks like #8 was created to fix the same problem that manifested itself slightly differently. The solution was merged into master with PR #20. However, as #19 calls out, the update has not been released to PyPI (nor has the version been incremented in __init__.py).

pyDOE2 was forked from this repo to release this fix and others to PyPI. Install using: pip install pyDOE2. I'm doing my import in the following way so I didn't have to change any of the rest of my code:

import pyDOE2 as pyDOE

@tisimst What's the plan on releasing this fix to PyPI? I saw your note on #17 saying that you've been too busy to make updates. I can understand that. Do you recommend moving to pyDOE2 permanently? Like the comment in #17, have you given thought to allowing other contributors on the repo? Thanks for the great package thus far, it's been great for all of my work in 2.7.

cruoti avatar Jan 23 '19 13:01 cruoti

From @cruti comments and because I'm using python 3. The current solution is to uninstall pyDOE and install pyDOE2.

maraujo avatar May 28 '19 16:05 maraujo

From @Cruti comments and because I'm using python 3. The current solution is to uninstall pyDOE and install pyDOE2.

hi my dear friend,I use pyDoe2 and everything be fine. Thank a lot !

rsyanting avatar Jul 10 '22 16:07 rsyanting