Skip to content

Commit

Permalink
fix dtype checking of data[col_name]
Browse files Browse the repository at this point in the history
  • Loading branch information
taeefnajib committed Jul 12, 2024
1 parent 45f47df commit a4f5973
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/ficto/core/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a4f5973

Please sign in to comment.