Skip to content

Commit

Permalink
fix issue #119 (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
gijzelaerr committed Jan 8, 2021
1 parent 83062d7 commit fb7d413
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
12 changes: 6 additions & 6 deletions monetdbe/_cffi/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def py_float(data: ffi.CData) -> float:
(lib.monetdbe_timestamp, "timestamp", np.dtype('=O'), "timestamp", py_timestamp, None),
]
numpy2monet_map = {numpy_type: (c_string, monet_type) for monet_type, _, numpy_type, c_string, _, _ in mappings}
monet_numpy_map = {monet_type: (c_string, converter, numpy_type, null_value) for
monet_type, _, numpy_type, c_string, converter, null_value in mappings}
monet_numpy_map = {monet_type: (sql_type, numpy_type, c_string, converter, null_value) for
monet_type, sql_type, numpy_type, c_string, converter, null_value in mappings}


def numpy_monetdb_map(numpy_type: np.dtype):
Expand All @@ -67,13 +67,13 @@ def extract(rcol: ffi.CData, r: int, text_factory: Optional[Callable[[str], Any]
The text_factory is optional, and wraps the value with a custom user supplied text function.
"""
cast_string, cast_function, numpy_type, monetdbe_null = monet_numpy_map[rcol.type]
col = ffi.cast(f"monetdbe_column_{cast_string} *", rcol)
_, _, c_string, converter, _ = monet_numpy_map[rcol.type]
col = ffi.cast(f"monetdbe_column_{c_string} *", rcol)
if col.is_null(col.data + r):
return None
else:
if cast_function:
result = cast_function(col.data[r])
if converter:
result = converter(col.data[r])
if rcol.type == lib.monetdbe_str and text_factory:
return text_factory(result)
else:
Expand Down
4 changes: 2 additions & 2 deletions monetdbe/_cffi/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def result_fetch_numpy(monetdbe_result: ffi.CData) -> Mapping[str, np.ma.MaskedA
for c in range(monetdbe_result.ncols):
rcol = Frontend.result_fetch(monetdbe_result, c)
name = make_string(rcol.name)
cast_string, cast_function, numpy_type, monetdbe_null = monet_numpy_map[rcol.type]
_, numpy_type, _, _, monetdbe_null = monet_numpy_map[rcol.type]

# for non float/int we for now first make a numpy object array which we then convert to the right numpy type
if numpy_type.type == np.object_:
Expand Down Expand Up @@ -219,7 +219,7 @@ def append(self, table: str, data: Mapping[str, np.ndarray], schema: str = 'sys'
work_column = ffi.new('monetdbe_column *')
work_type_string, work_type = numpy_monetdb_map(column_values.dtype)
if not work_type == existing_type:
existing_type_string = monet_numpy_map[existing_type][0]
existing_type_string = monet_numpy_map[existing_type][2]
error = f"Type '{work_type_string}' for appended column '{column_name}' " \
f"does not match table type '{existing_type_string}'"
raise exceptions.ProgrammingError(error)
Expand Down
2 changes: 1 addition & 1 deletion monetdbe/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _set_description(self):
from monetdbe._cffi.convert import make_string, monet_numpy_map

name = (make_string(rcol.name) for rcol in self._columns)
type_code = (monet_numpy_map[rcol.type][2] for rcol in self._columns)
type_code = (monet_numpy_map[rcol.type][0] for rcol in self._columns)

display_size = repeat(None)
internal_size = repeat(None)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_lite/test_dbapi05.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import numpy


class TestDescription(object):
def test_description(self, monetdbe_cursor):
Expand All @@ -9,4 +7,4 @@ def test_description(self, monetdbe_cursor):
def test_description_fields(self, monetdbe_cursor):
monetdbe_cursor.execute('select name from sys.tables')
assert monetdbe_cursor.description[0][0] == "name"
assert monetdbe_cursor.description[0][1] == numpy.dtype('O')
assert monetdbe_cursor.description[0][1] == "string"

0 comments on commit fb7d413

Please sign in to comment.