Skip to content
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

Columns with white space #149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bcpandas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ def build_format_file(
str(
col_num if not db_cols_order else db_cols_order[str(col_name)]
), # Server column order
str(col_name), # Server column name, optional as long as not blank
str(col_name).replace(
" ", r"\s"
), # Server column name, optional as long as not blank
collation, # Column collation
"\n",
]
Expand Down
22 changes: 22 additions & 0 deletions tests/test_to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,28 @@ def auto_injector_fixture(self, request):
setattr(self, name, request.getfixturevalue(name))


@pytest.mark.usefixtures("database")
def test_columns_with_spaces(sql_creds):
table_name = "tosql_column_scenarios_2"
df = pd.DataFrame(
{
"col 1": [1.5, 2.5, 3.5, 4.5],
"col 2": [5.5, 6.5, 7.5, 8.5],
"col3": [9.5, 10.5, 11.5, 12.5],
"col4": [13.5, 14.5, 15.5, 16.5],
}
)

to_sql(
df=df,
table_name=table_name,
creds=sql_creds,
if_exists="replace",
index=False,
sql_type="table",
)


class TestToSqlColumnScenarios(_BaseToSql):
"""
Various tests for scenarios where the dataframe columns don't map exactly to the database columns,
Expand Down
Loading