Skip to content

Commit

Permalink
resolving merge conflict 20240223
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobshaw42 committed Feb 24, 2024
2 parents 59c6071 + eaf730d commit 9535a8a
Show file tree
Hide file tree
Showing 9 changed files with 732 additions and 564 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Expand Up @@ -5,15 +5,15 @@ repos:
- id: identity
- id: check-hooks-apply
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.285'
rev: 'v0.2.2'
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [types-setuptools]
Expand All @@ -24,20 +24,20 @@ repos:
args:
- "--github"
- repo: https://github.com/adrienverge/yamllint
rev: v1.32.0
rev: v1.35.1
hooks:
- id: yamllint
args: ["--strict"]
types: [yaml]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- id: check-yaml
- id: debug-statements
- repo: https://github.com/zricethezav/gitleaks
rev: v8.17.0
rev: v8.18.2
hooks:
- id: gitleaks
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -160,9 +160,9 @@ Azure versions.
See the
[pyodbc docs](https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Windows)
for more on different driver versions.
- Python >= 3.7
- `pandas` >= 0.19
- `sqlalchemy` >= 1.0
- Python >= 3.8
- `pandas` >= 1.5
- `sqlalchemy` >= 1.4
- `pyodbc` as the
[supported DBAPI](https://docs.sqlalchemy.org/en/13/dialects/mssql.html#module-sqlalchemy.dialects.mssql.pyodbc)

Expand Down
31 changes: 18 additions & 13 deletions bcpandas/main.py
Expand Up @@ -26,6 +26,7 @@
BCPandasValueError,
get_delimiter,
get_quotechar,
sql_collation,
)
from bcpandas.utils import bcp, build_format_file, get_temp_file

Expand Down Expand Up @@ -206,18 +207,19 @@ def _create_table(
):
"""use pandas' own code to create the table and schema"""

sql_db = SQLDatabase(creds.engine, schema=schema)
table = SQLTable(
table_name,
sql_db,
frame=df,
index=False, # already set as new col earlier if index=True
if_exists=if_exists,
index_label=None,
schema=schema,
dtype=dtype,
)
table.create()
with creds.engine.begin() as conn:
sql_db = SQLDatabase(conn, schema=schema)
table = SQLTable(
table_name,
sql_db,
frame=df,
index=False, # already set as new col earlier if index=True
if_exists=if_exists,
index_label=None,
schema=schema,
dtype=dtype,
)
table.create()


def _handle_cols_for_append(
Expand Down Expand Up @@ -352,6 +354,7 @@ def to_sql(
quotechar: Optional[str] = None,
encoding: Optional[str] = None,
work_directory: Optional[Path] = None,
collation: str = sql_collation,
):
"""
Writes the pandas DataFrame to a SQL table or view.
Expand Down Expand Up @@ -463,7 +466,9 @@ def to_sql(
if_exists=if_exists,
)

fmt_file_txt = build_format_file(df=df, delimiter=delim, db_cols_order=cols_dict)
fmt_file_txt = build_format_file(
df=df, delimiter=delim, db_cols_order=cols_dict, collation=collation
)
with open(fmt_file_path, "w") as ff:
ff.write(fmt_file_txt)
logger.debug(f"Created BCP format file at {fmt_file_path}")
Expand Down
9 changes: 7 additions & 2 deletions bcpandas/utils.py
Expand Up @@ -160,7 +160,10 @@ def _escape(input_string: str) -> str:


def build_format_file(
df: pd.DataFrame, delimiter: str, db_cols_order: Optional[Dict[str, int]] = None
df: pd.DataFrame,
delimiter: str,
db_cols_order: Optional[Dict[str, int]] = None,
collation: str = sql_collation,
) -> str:
"""
Creates the non-xml SQL format file. Puts 4 spaces between each section.
Expand All @@ -179,6 +182,8 @@ def build_format_file(
Maps existing columns in the database to their ordinal position, i.e. the order of the columns in the db table.
1-indexed, so the first columns is 1, second is 2, etc.
Only needed if the order of the columns in the dataframe doesn't match the database.
collation: str, optional
Collation to be used in the format file. The default value is 'SQL_Latin1_General_CP1_CI_AS'
Returns
-------
Expand All @@ -202,7 +207,7 @@ def build_format_file(
str(col_name).replace(
" ", r"\s"
), # Server column name, optional as long as not blank
sql_collation, # Column collation
collation, # Column collation
"\n",
]
)
Expand Down
1 change: 0 additions & 1 deletion benchmarks/read_sql/conftest.py
Expand Up @@ -4,7 +4,6 @@
@author: ydima
"""


import time
import urllib

Expand Down

0 comments on commit 9535a8a

Please sign in to comment.