Skip to content
Snippets Groups Projects

TableConverter now converts int to float and vice versa to match the desired dtype.

Merged Daniel Hornung requested to merge f-convert-int-float into dev
1 unresolved thread
Files
2
@@ -312,8 +312,8 @@ class TableImporter():
.. note::
If columns are float, but should be integer or vice versa, this method converts the
respective columns in place.
If columns are integer, but should be float, this method converts the respective columns
in place.
Parameters
----------
@@ -323,14 +323,13 @@ class TableImporter():
"""
for key, datatype in self.datatypes.items():
# Check for castable numeric types first: We unconditionally cast float to int and vice
# versa, because CaosDB does not have different sizes anyway.
# Check for castable numeric types first: We unconditionally cast int to the default
# float, because CaosDB does not have different sizes anyway.
col_dtype = df.dtypes[key]
if not strict and not np.issubdtype(col_dtype, datatype):
issub = np.issubdtype
# These special cases should be fine.
if ((issub(col_dtype, np.integer) and issub(datatype, np.floating))
or (issub(col_dtype, np.floating) and issub(datatype, np.integer))):
if issub(col_dtype, np.integer) and issub(datatype, np.floating):
df[key] = df[key].astype(datatype)
# Now check each element
Loading