Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c6f09e8

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

File tree

Expand file treeCollapse file tree

1 file changed

+2
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+2
-4
lines changed

‎pandas_to_postgres/utilities.py

Copy file name to clipboardExpand all lines: pandas_to_postgres/utilities.py
+2-4Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.