Skip to content
Snippets Groups Projects
Verified Commit 61a31fff authored by Daniel Hornung's avatar Daniel Hornung
Browse files

FIX: Don't cast float to int.

parent d07196be
No related branches found
No related tags found
2 merge requests!39Release 0.4.0,!34TableConverter now converts int to float and vice versa to match the desired dtype.
Pipeline #19891 failed
......@@ -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
......
......@@ -218,12 +218,10 @@ class XLSImporterTest(TableImporterTest):
"float_as_float": float,
"int_as_float": float,
"int_as_int": int,
"float_as_int": int,
}
)
df = importer.read_xls(os.path.join(os.path.dirname(__file__), "data", "datatypes.xlsx"))
assert np.issubdtype(df.loc[0, "int_as_float"], float)
assert df.loc[1, "float_as_int"] == 6 # This is an acceptable rounding error.
class CSVImporterTest(TableImporterTest):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment