99from pandas .lib import is_bool_array
1010from pandas .types .generic import ABCIndexClass , ABCSeries , ABCDataFrame
1111from 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 )
1314
1415# 16 byte long hashing key
1516_default_hash_key = '0123456789123456'
1617
1718
1819def _combine_hash_arrays (arrays , num_items ):
19- "Should be the same as CPython's tupleobject.c"
20- first = next (arrays )
20+ """
21+ Parameters
22+ ----------
23+ arrays : generator
24+ num_items : int
25+
26+ Should be the same as CPython's tupleobject.c
27+ """
28+ try :
29+ first = next (arrays )
30+ except StopIteration :
31+ return np .array ([], dtype = np .uint64 )
32+
2133 arrays = itertools .chain ([first ], arrays )
2234
23- mult = np .zeros_like ( first ) + np . uint64 (1000003 )
35+ mult = np .uint64 (1000003 )
2436 out = np .zeros_like (first ) + np .uint64 (0x345678 )
2537 for i , a in enumerate (arrays ):
2638 inverse_i = num_items - i
@@ -135,11 +147,11 @@ def _hash_lists(vals, encoding='utf8', hash_key=None):
135147
136148def hash_tuples (vals , encoding = 'utf8' , hash_key = None ):
137149 """
138- Hash an MultiIndex / array_of_tuples efficiently
150+ Hash an MultiIndex / list-of-tuples efficiently
139151
140152 Parameters
141153 ----------
142- vals : MultiIndex, ndarray of tuples, or single tuple
154+ vals : MultiIndex, list-of- tuples, or single tuple
143155 encoding : string, default 'utf8'
144156 hash_key : string key to encode, default to _default_hash_key
145157
@@ -152,6 +164,8 @@ def hash_tuples(vals, encoding='utf8', hash_key=None):
152164 if isinstance (vals , tuple ):
153165 vals = [vals ]
154166 is_tuple = True
167+ elif not is_list_like (vals ):
168+ raise TypeError ("must be convertible to a list-of-tuples" )
155169
156170 if not isinstance (vals , MultiIndex ):
157171 vals = MultiIndex .from_tuples (vals )
0 commit comments