Skip to content

Commit 89256f0

Browse files
author
Christopher C. Aycock
committed
Test 8-bit integers and raise error on 16-bit floats; add comments
1 parent 0ad1687 commit 89256f0

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

pandas/src/joins_func_helper.pxi.in

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def asof_join_{{on_dtype}}(ndarray[{{on_dtype}}] left_values,
169169
#----------------------------------------------------------------------
170170

171171
def stringify(ndarray[object, ndim=2] xt):
172+
""" Invokes .tostring() on each array entry within a 2D array. """
172173
cdef:
173174
Py_ssize_t n
174175
ndarray[object] result

pandas/tools/merge.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ def _asof_by_function(on_type, by_type):
949949
'int32': 'int32_t',
950950
'int16': 'int16_t',
951951
'int64': 'int64_t',
952-
'float16': 'float',
952+
'float16': 'error',
953953
'float32': 'float',
954954
'float64': 'double',
955955
}
@@ -959,6 +959,8 @@ def _get_cython_type(dtype):
959959
""" Given a dtype, return a C name like 'int64_t' or 'double' """
960960
type_name = _get_dtype(dtype).name
961961
ctype = _cyton_types.get(type_name, 'object')
962+
if ctype == 'error':
963+
raise MergeError('unsupported type: ' + type_name)
962964
return ctype
963965

964966

@@ -1063,6 +1065,7 @@ def _get_join_indexers(self):
10631065
def flip_stringify(xs):
10641066
""" flip an array of arrays and string-ify contents """
10651067
xt = np.transpose(xs)
1068+
# numpy arrays aren't hashable, so we convert to a string
10661069
return _join.stringify(_ensure_object(xt))
10671070

10681071
# values to compare

pandas/tools/tests/test_merge_asof.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -565,17 +565,17 @@ def test_on_float(self):
565565

566566
def test_on_specialized_type(self):
567567
# GH13936
568-
for dtype in [np.uint16, np.uint32, np.uint64,
569-
np.int16, np.int32, np.int64,
568+
for dtype in [np.uint8, np.uint16, np.uint32, np.uint64,
569+
np.int8, np.int16, np.int32, np.int64,
570570
np.float32, np.float64]:
571571
df1 = pd.DataFrame({
572-
'value': [5, 2, 25, 300, 78, 1040, 79],
572+
'value': [5, 2, 25, 100, 78, 120, 79],
573573
'symbol': list("ABCDEFG")},
574574
columns=['symbol', 'value'])
575575
df1.value = dtype(df1.value)
576576

577577
df2 = pd.DataFrame({
578-
'value': [0, 100, 1000, 10000],
578+
'value': [0, 80, 120, 125],
579579
'result': list('xyzw')},
580580
columns=['value', 'result'])
581581
df2.value = dtype(df2.value)
@@ -586,7 +586,7 @@ def test_on_specialized_type(self):
586586

587587
expected = pd.DataFrame({
588588
'symbol': list("BACEGDF"),
589-
'value': [2, 5, 25, 78, 79, 300, 1040],
589+
'value': [2, 5, 25, 78, 79, 100, 120],
590590
'result': list('xxxxxyz')},
591591
columns=['symbol', 'value', 'result'])
592592
expected.value = dtype(expected.value)
@@ -595,18 +595,18 @@ def test_on_specialized_type(self):
595595

596596
def test_on_specialized_type_by_int(self):
597597
# GH13936
598-
for dtype in [np.uint16, np.uint32, np.uint64,
599-
np.int16, np.int32, np.int64,
598+
for dtype in [np.uint8, np.uint16, np.uint32, np.uint64,
599+
np.int8, np.int16, np.int32, np.int64,
600600
np.float32, np.float64]:
601601
df1 = pd.DataFrame({
602-
'value': [5, 2, 25, 300, 78, 1040, 79],
602+
'value': [5, 2, 25, 100, 78, 120, 79],
603603
'key': [1, 2, 3, 2, 3, 1, 2],
604604
'symbol': list("ABCDEFG")},
605605
columns=['symbol', 'key', 'value'])
606606
df1.value = dtype(df1.value)
607607

608608
df2 = pd.DataFrame({
609-
'value': [0, 100, 1000, 10000],
609+
'value': [0, 80, 120, 125],
610610
'key': [1, 2, 2, 3],
611611
'result': list('xyzw')},
612612
columns=['value', 'key', 'result'])
@@ -619,7 +619,7 @@ def test_on_specialized_type_by_int(self):
619619
expected = pd.DataFrame({
620620
'symbol': list("BACEGDF"),
621621
'key': [2, 1, 3, 3, 2, 2, 1],
622-
'value': [2, 5, 25, 78, 79, 300, 1040],
622+
'value': [2, 5, 25, 78, 79, 100, 120],
623623
'result': [np.nan, 'x', np.nan, np.nan, np.nan, 'y', 'x']},
624624
columns=['symbol', 'key', 'value', 'result'])
625625
expected.value = dtype(expected.value)

0 commit comments

Comments
 (0)