9
9
from pandas .lib import is_bool_array
10
10
from pandas .types .generic import ABCIndexClass , ABCSeries , ABCDataFrame
11
11
from pandas .types .common import (is_categorical_dtype , is_numeric_dtype ,
12
- is_datetime64_dtype , is_timedelta64_dtype )
12
+ is_datetime64_dtype , is_timedelta64_dtype ,
13
+ is_list_like )
13
14
14
15
# 16 byte long hashing key
15
16
_default_hash_key = '0123456789123456'
@@ -20,7 +21,7 @@ def _combine_hash_arrays(arrays, num_items):
20
21
first = next (arrays )
21
22
arrays = itertools .chain ([first ], arrays )
22
23
23
- mult = np .zeros_like ( first ) + np . uint64 (1000003 )
24
+ mult = np .uint64 (1000003 )
24
25
out = np .zeros_like (first ) + np .uint64 (0x345678 )
25
26
for i , a in enumerate (arrays ):
26
27
inverse_i = num_items - i
@@ -135,11 +136,11 @@ def _hash_lists(vals, encoding='utf8', hash_key=None):
135
136
136
137
def hash_tuples (vals , encoding = 'utf8' , hash_key = None ):
137
138
"""
138
- Hash an MultiIndex / array_of_tuples efficiently
139
+ Hash an MultiIndex / list-of-tuples efficiently
139
140
140
141
Parameters
141
142
----------
142
- vals : MultiIndex, ndarray of tuples, or single tuple
143
+ vals : MultiIndex, list-of- tuples, or single tuple
143
144
encoding : string, default 'utf8'
144
145
hash_key : string key to encode, default to _default_hash_key
145
146
@@ -152,6 +153,8 @@ def hash_tuples(vals, encoding='utf8', hash_key=None):
152
153
if isinstance (vals , tuple ):
153
154
vals = [vals ]
154
155
is_tuple = True
156
+ elif not is_list_like (vals ):
157
+ raise TypeError ("must be convertible to a list-of-tuples" )
155
158
156
159
if not isinstance (vals , MultiIndex ):
157
160
vals = MultiIndex .from_tuples (vals )
0 commit comments