-
Notifications
You must be signed in to change notification settings - Fork 49
support "bool[pyarrow]" columns #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 26 commits
1dca4d2
4dd6c96
bb7d658
81b9e20
04c86e6
925204e
2831393
9a2b436
3e284ca
ee2b48d
4b6c6a6
3c77ad4
a5df3eb
bb0b286
e3acb2e
e5f0e39
1c1b8db
d3b6efc
37e0edb
9993a42
33112f0
a4a0289
39aa72a
344be43
09bcc1f
568d2ff
5dc4c25
ae0cca8
31ab7b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import csv | ||
| import logging | ||
| import os | ||
| from copy import copy | ||
| from pathlib import Path | ||
| from textwrap import dedent | ||
| from typing import Dict, List, Optional, Union | ||
|
|
@@ -441,7 +442,20 @@ def to_sql( | |
| # save to temp path | ||
| csv_file_path = get_temp_file(work_directory) | ||
| # replace bools with 1 or 0, this is what pandas native does when writing to SQL Server | ||
| df.replace({True: 1, False: 0}).to_csv( | ||
| # attention: the `(lambda col: lambda...)(copy(col))` part looks odd but is | ||
| # needed to ensure loop iterations create lambdas working on different columns. | ||
| df_out = df.assign( | ||
| **{ | ||
| col: (lambda col: lambda df: df[col].map({True: 1, False: 0}).astype(pd.Int8Dtype()))( | ||
| copy(col) | ||
| ) | ||
windiana42 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for col, dtype in df.dtypes[ | ||
| (df.dtypes == "bool[pyarrow]") | (df.dtypes == "bool") | (df.dtypes == "boolean") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the most ergonomic way of comparing dtypes in pandas? 🤔 haven't used pandas in a while 👀
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "==" operator for pandas dtypes does quite some magic. That is why it cannot be replaced with "in". I was hoping that it actually knows a generic "bool" which matches to all types of booleans. However, the nullable boolean is actually called "boolean" and not "bool[python]". |
||
| ].items() | ||
| } | ||
| ) | ||
| # write to CSV | ||
| df_out.replace({True: 1, False: 0}).to_csv( | ||
windiana42 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| path_or_buf=csv_file_path, | ||
| sep=delim, | ||
| header=False, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this comment