Skip to content

Commit ffcf0c2

Browse files
author
Christopher C. Aycock
committed
Added test to reject float16; fixed typos
1 parent 1f208a8 commit ffcf0c2

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

pandas/tools/merge.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ def _asof_by_function(on_type, by_type):
10131013
'object': _ensure_object,
10141014
}
10151015

1016-
_cyton_types = {
1016+
_cython_types = {
10171017
'uint8': 'uint8_t',
10181018
'uint32': 'uint32_t',
10191019
'uint16': 'uint16_t',
@@ -1031,7 +1031,7 @@ def _asof_by_function(on_type, by_type):
10311031
def _get_cython_type(dtype):
10321032
""" Given a dtype, return a C name like 'int64_t' or 'double' """
10331033
type_name = _get_dtype(dtype).name
1034-
ctype = _cyton_types.get(type_name, 'object')
1034+
ctype = _cython_types.get(type_name, 'object')
10351035
if ctype == 'error':
10361036
raise MergeError('unsupported type: ' + type_name)
10371037
return ctype

pandas/tools/tests/test_merge_asof.py

+29-21
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def test_on_specialized_type(self):
657657
# GH13936
658658
for dtype in [np.uint8, np.uint16, np.uint32, np.uint64,
659659
np.int8, np.int16, np.int32, np.int64,
660-
np.float32, np.float64]:
660+
np.float16, np.float32, np.float64]:
661661
df1 = pd.DataFrame({
662662
'value': [5, 2, 25, 100, 78, 120, 79],
663663
'symbol': list("ABCDEFG")},
@@ -672,22 +672,26 @@ def test_on_specialized_type(self):
672672

673673
df1 = df1.sort_values('value').reset_index(drop=True)
674674

675-
result = pd.merge_asof(df1, df2, on='value')
675+
if dtype == np.float16:
676+
with self.assertRaises(MergeError):
677+
pd.merge_asof(df1, df2, on='value')
678+
else:
679+
result = pd.merge_asof(df1, df2, on='value')
676680

677-
expected = pd.DataFrame({
678-
'symbol': list("BACEGDF"),
679-
'value': [2, 5, 25, 78, 79, 100, 120],
680-
'result': list('xxxxxyz')},
681-
columns=['symbol', 'value', 'result'])
682-
expected.value = dtype(expected.value)
681+
expected = pd.DataFrame({
682+
'symbol': list("BACEGDF"),
683+
'value': [2, 5, 25, 78, 79, 100, 120],
684+
'result': list('xxxxxyz')},
685+
columns=['symbol', 'value', 'result'])
686+
expected.value = dtype(expected.value)
683687

684-
assert_frame_equal(result, expected)
688+
assert_frame_equal(result, expected)
685689

686690
def test_on_specialized_type_by_int(self):
687691
# GH13936
688692
for dtype in [np.uint8, np.uint16, np.uint32, np.uint64,
689693
np.int8, np.int16, np.int32, np.int64,
690-
np.float32, np.float64]:
694+
np.float16, np.float32, np.float64]:
691695
df1 = pd.DataFrame({
692696
'value': [5, 2, 25, 100, 78, 120, 79],
693697
'key': [1, 2, 3, 2, 3, 1, 2],
@@ -704,17 +708,21 @@ def test_on_specialized_type_by_int(self):
704708

705709
df1 = df1.sort_values('value').reset_index(drop=True)
706710

707-
result = pd.merge_asof(df1, df2, on='value', by='key')
708-
709-
expected = pd.DataFrame({
710-
'symbol': list("BACEGDF"),
711-
'key': [2, 1, 3, 3, 2, 2, 1],
712-
'value': [2, 5, 25, 78, 79, 100, 120],
713-
'result': [np.nan, 'x', np.nan, np.nan, np.nan, 'y', 'x']},
714-
columns=['symbol', 'key', 'value', 'result'])
715-
expected.value = dtype(expected.value)
716-
717-
assert_frame_equal(result, expected)
711+
if dtype == np.float16:
712+
with self.assertRaises(MergeError):
713+
pd.merge_asof(df1, df2, on='value', by='key')
714+
else:
715+
result = pd.merge_asof(df1, df2, on='value', by='key')
716+
717+
expected = pd.DataFrame({
718+
'symbol': list("BACEGDF"),
719+
'key': [2, 1, 3, 3, 2, 2, 1],
720+
'value': [2, 5, 25, 78, 79, 100, 120],
721+
'result': [np.nan, 'x', np.nan, np.nan, np.nan, 'y', 'x']},
722+
columns=['symbol', 'key', 'value', 'result'])
723+
expected.value = dtype(expected.value)
724+
725+
assert_frame_equal(result, expected)
718726

719727
def test_on_float_by_int(self):
720728
# type specialize both "by" and "on" parameters

0 commit comments

Comments
 (0)