python build in function_numba-typengerror:无法确定numba类型<class'builtin_function_或_method'>...

我有一个简单的功能,排名扑克手(手是字符串)。

我用rA,rB = rank(a),rank(b)调用它,这里是我的实现。如果没有@jit(nopython=True),它可以很好地工作,但是如果使用它,它会失败:File "C:/Users/avi_na/Desktop/poker.py", line 190, in

rA,rB = rank(a),rank(b)

File "C:\Continuum\anaconda3\lib\site-packages\numba\dispatcher.py", line 344, in _compile_for_args

reraise(type(e), e, None)

File "C:\Continuum\anaconda3\lib\site-packages\numba\six.py", line 658, in reraise

raise value.with_traceback(tb)

TypingError: cannot determine Numba type of from numba import jit

from numba.types import string

@jit(nopython=True)

def rank(hand):

# assert(len(hand) == 5)

rank = "N/A"

p = pd.Series([h[0] for h in hand]).value_counts()

v = sorted(set(pd.Series([h[0] for h in hand]).values), reverse=True)

s = sorted(hand, key=lambda k:k[0])

z = zip(s,s[1:])

if all(x[0]==y[0]-1 for x,y in z):

rank = "Straight "

if len(set([h[1] for h in hand])) == 1:

rank += "Flush "

if "Straight Flush" in rank and sum([h[0] for h in hand]) == sum([10,11,12,13,14]):

rank = "Royal Flush"

elif p[p.idxmax()] == 4:

rank = "4 Of A Kind : %d" % p.idxmax()

elif p[p.idxmax()] == 3 and p[p.idxmin()] == 1:

rank = "3 Of A Kind : %d" % p.idxmax()

elif p[p.idxmax()] == 3 and p[p.idxmin()] == 2:

rank = "Full House : %d,%d" % (p.idxmax(), p.idxmin())

elif p[p.idxmax()] == 2:

max2 = p.nlargest(2)

if list(max2) == [2,2]:

max2 = sorted(list(max2.keys()), reverse=True)

rank = "2 Pairs : %d,%d" % (max2[0],max2[1])

else:

rank = "Pair : %d" % p.idxmax()

else:

rank = "High Card : %d" % v[0]

return rank

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值