Skip to content

Commit e1696d7

Browse files
committed
Refactor to replace applymap and prevent unintended int-to-float conversion.
1 parent 05c4ae1 commit e1696d7

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

genie/load.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,13 @@ def _generate_primary_key(
241241
Returns:
242242
pd.DataFrame: The dataframe with primary_key column added
243243
"""
244-
# generate primary key column for original database
245-
dataset[primary_key_cols] = dataset[primary_key_cols].applymap(str)
246-
# replace NAs with emtpy string
247-
dataset[primary_key_cols] = dataset[primary_key_cols].fillna("")
248244
if dataset.empty:
249245
dataset[primary_key] = ""
250246
else:
247+
# Convert to string and join, converting NaN values to empty strings
248+
# When using apply(axis=1), x is a Series (row) - iterate over each value
251249
dataset[primary_key] = dataset[primary_key_cols].apply(
252-
lambda x: " ".join(x), axis=1
250+
lambda x: " ".join("" if pd.isna(v) else str(v) for v in x), axis=1
253251
)
254252
return dataset
255253

0 commit comments

Comments
 (0)