From a4f597389c96feca52c47898daac97db61bdb464 Mon Sep 17 00:00:00 2001 From: taeefnajib Date: Sat, 13 Jul 2024 05:22:49 +0600 Subject: [PATCH] fix dtype checking of data[col_name] --- src/ficto/core/generate.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ficto/core/generate.py b/src/ficto/core/generate.py index 00d3951..03eaa4d 100644 --- a/src/ficto/core/generate.py +++ b/src/ficto/core/generate.py @@ -241,20 +241,16 @@ def create_dataframe(dataconfig, numrows): step = column.get("step", 1) data[col_name] = generate_custom_sequence(start, step, numrows) - # Function to check if a column is already numeric - def is_numeric(series): - return pd.api.types.is_numeric_dtype(series) - # Convert column to specified datatype # Skip conversion if the column is already in the desired datatype if col_datatype == "int": - if not is_numeric(data[col_name]): + if not pd.api.types.is_numeric_dtype(pd.Series(data[col_name])): data[col_name] = pd.to_numeric(data[col_name], errors="coerce").astype(int) elif col_datatype == "float": - if not is_numeric(data[col_name]): + if not pd.api.types.is_numeric_dtype(pd.Series(data[col_name])): data[col_name] = pd.to_numeric(data[col_name], errors="coerce").astype(float) elif col_datatype == "string": - if not pd.api.types.is_string_dtype(data[col_name]): + if not pd.api.types.is_string_dtype(pd.Series(data[col_name])): data[col_name] = data[col_name].astype(str) df = pd.DataFrame(data)