rethinkpriorities / squigglepy

Squiggle programming language for intuitive probabilistic estimation features in Python
MIT License
65 stars 8 forks source link

squigglepy doesn't handle numpy integers #5

Closed joel-becker closed 1 year ago

joel-becker commented 1 year ago

not usually a python user, so maybe it is standard practice to account for integers and numpy integers separately? raising as issue in case not.

hopefully the below example is clear:

>>> distribution 
<Distribution> lognorm(mean=-1.26, sd=1.61)
>>> n
9
>>> distribution @ 9
array([0.0225612 , 0.46752896, 2.20596081, 0.04523069, 0.12903551,
       0.01490158, 2.06714022, 1.97190706, 0.1854637 ])
>>> distribution @ n
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/joel/Library/Python/3.9/lib/python/site-packages/squigglepy/distributions.py", line 57, in __matmul__
    raise ValueError
ValueError
>>> type(n)
<class 'numpy.int64'>
>>> type(9)
<class 'int'>
>>> n = int(n)
>>> distribution @ n
array([0.76783902, 0.07521819, 0.35157636, 0.06835797, 0.01786806,
       1.28000189, 2.06632018, 1.06315067, 0.24975447])

the error stems from this line in squigglepy/distributions.py.

peterhurford commented 1 year ago

Thanks. I recognize this as a bug and will commit to fixing it in the next version.

peterhurford commented 1 year ago

@joel-becker Now live on pip in v0.24!