Skip to content

Commit

Permalink
Added test to reject float16; fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher C. Aycock committed Dec 16, 2016
1 parent 1f208a8 commit ffcf0c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
4 changes: 2 additions & 2 deletions pandas/tools/merge.py
Expand Up @@ -1013,7 +1013,7 @@ def _asof_by_function(on_type, by_type):
'object': _ensure_object,
}

_cyton_types = {
_cython_types = {
'uint8': 'uint8_t',
'uint32': 'uint32_t',
'uint16': 'uint16_t',
Expand All @@ -1031,7 +1031,7 @@ def _asof_by_function(on_type, by_type):
def _get_cython_type(dtype):
""" Given a dtype, return a C name like 'int64_t' or 'double' """
type_name = _get_dtype(dtype).name
ctype = _cyton_types.get(type_name, 'object')
ctype = _cython_types.get(type_name, 'object')
if ctype == 'error':
raise MergeError('unsupported type: ' + type_name)
return ctype
Expand Down
50 changes: 29 additions & 21 deletions pandas/tools/tests/test_merge_asof.py
Expand Up @@ -657,7 +657,7 @@ def test_on_specialized_type(self):
# GH13936
for dtype in [np.uint8, np.uint16, np.uint32, np.uint64,
np.int8, np.int16, np.int32, np.int64,
np.float32, np.float64]:
np.float16, np.float32, np.float64]:
df1 = pd.DataFrame({
'value': [5, 2, 25, 100, 78, 120, 79],
'symbol': list("ABCDEFG")},
Expand All @@ -672,22 +672,26 @@ def test_on_specialized_type(self):

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

result = pd.merge_asof(df1, df2, on='value')
if dtype == np.float16:
with self.assertRaises(MergeError):
pd.merge_asof(df1, df2, on='value')
else:
result = pd.merge_asof(df1, df2, on='value')

expected = pd.DataFrame({
'symbol': list("BACEGDF"),
'value': [2, 5, 25, 78, 79, 100, 120],
'result': list('xxxxxyz')},
columns=['symbol', 'value', 'result'])
expected.value = dtype(expected.value)
expected = pd.DataFrame({
'symbol': list("BACEGDF"),
'value': [2, 5, 25, 78, 79, 100, 120],
'result': list('xxxxxyz')},
columns=['symbol', 'value', 'result'])
expected.value = dtype(expected.value)

assert_frame_equal(result, expected)
assert_frame_equal(result, expected)

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

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

result = pd.merge_asof(df1, df2, on='value', by='key')

expected = pd.DataFrame({
'symbol': list("BACEGDF"),
'key': [2, 1, 3, 3, 2, 2, 1],
'value': [2, 5, 25, 78, 79, 100, 120],
'result': [np.nan, 'x', np.nan, np.nan, np.nan, 'y', 'x']},
columns=['symbol', 'key', 'value', 'result'])
expected.value = dtype(expected.value)

assert_frame_equal(result, expected)
if dtype == np.float16:
with self.assertRaises(MergeError):
pd.merge_asof(df1, df2, on='value', by='key')
else:
result = pd.merge_asof(df1, df2, on='value', by='key')

expected = pd.DataFrame({
'symbol': list("BACEGDF"),
'key': [2, 1, 3, 3, 2, 2, 1],
'value': [2, 5, 25, 78, 79, 100, 120],
'result': [np.nan, 'x', np.nan, np.nan, np.nan, 'y', 'x']},
columns=['symbol', 'key', 'value', 'result'])
expected.value = dtype(expected.value)

assert_frame_equal(result, expected)

def test_on_float_by_int(self):
# type specialize both "by" and "on" parameters
Expand Down

0 comments on commit ffcf0c2

Please sign in to comment.