Skip to content

Commit c6f09e8

Browse files
committed
Change comparing str("nan") to pd.isna()
1 parent 04eacaf commit c6f09e8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

pandas_to_postgres/utilities.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,11 @@ def cast_pandas(df, sql_table):
101101
for col in sql_table.columns:
102102
if str(col.type) in ["INTEGER", "BIGINT"]:
103103
df[col.name] = df[col.name].apply(
104-
# np.nan are not comparable, so use str value
105-
lambda x: None if str(x) == "nan" else int(x),
106-
convert_dtype=False,
104+
lambda x: None if pd.isna(x) else int(x), convert_dtype=False
107105
)
108106
elif str(col.type) == "BOOLEAN":
109107
df[col.name] = df[col.name].apply(
110-
lambda x: None if str(x) == "nan" else bool(x), convert_dtype=False
108+
lambda x: None if pd.isna(x) else bool(x), convert_dtype=False
111109
)
112110

113111
return df

0 commit comments

Comments
 (0)