Skip to content

Commit

Permalink
Merge pull request #399 from sanders41/name-only
Browse files Browse the repository at this point in the history
Make continue_on_error and verbose name only parameters
  • Loading branch information
sanders41 authored May 25, 2023
2 parents cb2d50a + 17f06ef commit edcdf72
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
42 changes: 31 additions & 11 deletions sas7bdat_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@


def batch_to_csv(
file_dicts: list[dict[str, str | Path]], continue_on_error: bool = False, verbose: bool = True
file_dicts: list[dict[str, str | Path]],
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
"""Converts a batch of sas7bdat and/or xpt files to csv files.
Expand Down Expand Up @@ -51,7 +54,10 @@ def batch_to_csv(


def batch_to_parquet(
file_dicts: list[dict[str, str | Path]], continue_on_error: bool = False, verbose: bool = True
file_dicts: list[dict[str, str | Path]],
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
"""Converts a batch of sas7bdat and/or xpt files to parquet files.
Expand Down Expand Up @@ -88,7 +94,10 @@ def batch_to_parquet(


def batch_to_excel(
file_dicts: list[dict[str, str | Path]], continue_on_error: bool = False, verbose: bool = True
file_dicts: list[dict[str, str | Path]],
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
"""Converts a batch of sas7bdat and/or xpt files to xlsx files.
Expand Down Expand Up @@ -125,7 +134,10 @@ def batch_to_excel(


def batch_to_json(
file_dicts: list[dict[str, str | Path]], continue_on_error: bool = False, verbose: bool = True
file_dicts: list[dict[str, str | Path]],
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
"""Converts a batch of sas7bdat and/or xpt files to json files.
Expand Down Expand Up @@ -162,7 +174,10 @@ def batch_to_json(


def batch_to_xml(
file_dicts: list[dict[str, str | Path]], continue_on_error: bool = False, verbose: bool = True
file_dicts: list[dict[str, str | Path]],
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
"""Converts a batch of sas7bdat and/or xpt files to xml files.
Expand Down Expand Up @@ -250,6 +265,7 @@ def batch_to_xml(
def dir_to_csv(
dir_path: str | Path,
export_path: str | Path | None = None,
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
Expand All @@ -265,12 +281,13 @@ def dir_to_csv(
a file conversion error instead of raising an exception. Default = False
verbose: Increases the output. Default = True
"""
_walk_dir("csv", dir_path, continue_on_error, export_path, verbose)
_walk_dir("csv", dir_path, export_path, continue_on_error, verbose)


def dir_to_excel(
dir_path: str | Path,
export_path: str | Path | None = None,
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
Expand All @@ -286,12 +303,13 @@ def dir_to_excel(
a file conversion error instead of raising an exception. Default = False
verbose: Increases the output. Default = True
"""
_walk_dir("xlsx", dir_path, continue_on_error, export_path, verbose)
_walk_dir("xlsx", dir_path, export_path, continue_on_error, verbose)


def dir_to_json(
dir_path: str | Path,
export_path: str | Path | None = None,
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
Expand All @@ -307,12 +325,13 @@ def dir_to_json(
a file conversion error instead of raising an exception. Default = False
verbose: Increases the output. Default = True
"""
_walk_dir("json", dir_path, continue_on_error, export_path, verbose)
_walk_dir("json", dir_path, export_path, continue_on_error, verbose)


def dir_to_parquet(
dir_path: str | Path,
export_path: str | Path | None = None,
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
Expand All @@ -328,12 +347,13 @@ def dir_to_parquet(
a file conversion error instead of raising an exception. Default = False
verbose: Increases the output. Default = True
"""
_walk_dir("parquet", dir_path, continue_on_error, export_path, verbose)
_walk_dir("parquet", dir_path, export_path, continue_on_error, verbose)


def dir_to_xml(
dir_path: str | Path,
export_path: str | Path | None = None,
*,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
Expand All @@ -349,7 +369,7 @@ def dir_to_xml(
a file conversion error instead of raising an exception. Default = False
verbose: Increases the output. Default = True
"""
_walk_dir("xml", dir_path, continue_on_error, export_path, verbose)
_walk_dir("xml", dir_path, export_path, continue_on_error, verbose)


def to_csv(sas7bdat_file: str | Path, export_file: str | Path) -> None:
Expand Down Expand Up @@ -538,8 +558,8 @@ def _rise_on_invalid_file_dict(file_dict: dict[str, str | Path]) -> None:
def _walk_dir(
file_type: str,
dir_path: str | Path,
continue_on_error: bool,
export_path: str | Path | None = None,
continue_on_error: bool = False,
verbose: bool = True,
) -> None:
path = dir_path if isinstance(dir_path, Path) else Path(dir_path)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sas7bdat_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2783,7 +2783,7 @@ def test_walk_dir_sas(tmpdir, sas7bdat_dir, file_type):
for sas_file in sas_files:
shutil.copy(sas_file, tmpdir)

converter._walk_dir(file_type, tmpdir, False)
converter._walk_dir(file_type, tmpdir)
sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".sas7bdat"])
convert_counter = len(
[name for name in Path(tmpdir).iterdir() if name.suffix == f".{file_type}"]
Expand All @@ -2798,7 +2798,7 @@ def test_walk_dir_xpt(tmpdir, xpt_dir, file_type):
for xpt_file in xpt_files:
shutil.copy(xpt_file, tmpdir)

converter._walk_dir(file_type, tmpdir, False)
converter._walk_dir(file_type, tmpdir)
xpt_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".xpt"])
convert_counter = len(
[name for name in Path(tmpdir).iterdir() if name.suffix == f".{file_type}"]
Expand Down

0 comments on commit edcdf72

Please sign in to comment.