Skip to content

Commit

Permalink
Merge pull request #149 from jacobshaw42/columns_with_white_space
Browse files Browse the repository at this point in the history
Columns with white space
  • Loading branch information
yehoshuadimarsky authored Feb 25, 2024
2 parents eaf730d + 9535a8a commit 7b471db
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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

0 comments on commit 7b471db

Please sign in to comment.