Skip to content

Commit

Permalink
feat: add sep choice for output
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoBousseau committed Jul 27, 2022
1 parent af297ff commit c07cd73
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ docker build -t data-selector .
Once built, you can run the container locally with the following command line:
```sh
docker run -ti --rm -v <your_path>:/DATA data-selector select_cli -i DATA/<your_file> -o DATA/<out_name> -f -S <path_to_select_param> -D <path_to_delete_param> -sD <path_to_select_data_param>
docker run -ti --rm -v <your_path>:/DATA data-selector select_cli -i DATA/<your_file> -o DATA/<out_name> -f -s <file_sep> -S <path_to_select_param> -D <path_to_delete_param> -sD <path_to_select_data_param>
```
-v allows to mount a volume and to use your local data on the docker environment.
Expand All @@ -192,6 +192,8 @@ docker run -ti --rm -v <your_path>:/DATA data-selector select_cli -i DATA/<your
**out_name**: The name you want to give to the output file.
**file_sep**: File separator of the output file.
**path_to_select_param**: Path towards json parametrization file.
**path_to_delete_param**: Path towards json parametrization file.
Expand Down
11 changes: 11 additions & 0 deletions src/data_selector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def version():
default='csv',
help="File format of the output (csv, json).",
)
@click.option(
"-s",
"--file_sep",
"file_sep",
type=str,
required=False,
default=',',
help="File separator (csv).",
)
@click.option(
"-S",
"--select",
Expand Down Expand Up @@ -91,6 +100,7 @@ def select_cli(
path_columns_to_keep: str,
path_columns_to_delete: str,
path_to_data_and_columns: str,
file_sep: str,
data_frame=None
):
"""Start service to select Data to Keep/Delete"""
Expand All @@ -103,6 +113,7 @@ def select_cli(
path_columns_to_keep,
path_columns_to_delete,
path_to_data_and_columns,
file_sep,
data_frame
)

Expand Down
18 changes: 12 additions & 6 deletions src/data_selector/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def select(
path_columns_to_keep=None,
path_columns_to_delete=None,
path_to_data_and_columns=None,
file_sep=',',
data_frame=None
) -> None:
"""Documentation:
Expand All @@ -32,7 +33,7 @@ def select(
with open(path_columns_to_keep) as d:
param_dict = json.load(d)
list_col_names: list[str] = [value for value in param_dict['column_names'].values()]
data_frame = data_frame.reindex(columns=list_col_names)
data_frame = select_column(data_frame, list_col_names)

if path_columns_to_delete is not None:

Expand All @@ -53,7 +54,8 @@ def select(
output_file,
overwrite,
format_choice,
input_format
input_format,
file_sep
)


Expand All @@ -62,7 +64,8 @@ def save(
output_file: str,
overwrite: bool,
format_choice=None,
input_format=None
input_format=None,
file_sep=','
) -> None:
"""Documentation:
inputs:
Expand All @@ -76,7 +79,7 @@ def save(
format_choice = input_format

if format_choice == "csv":
data_frame.to_csv(output_file, index=False, sep=";")
data_frame.to_csv(output_file, index=False, sep=file_sep)
print("File has been saved. End of the service.")

elif format_choice == "json":
Expand Down Expand Up @@ -111,8 +114,11 @@ def delete_column(
returns the new DataFrame.
"""

df_res: df = data_frame.drop(columns=List_of_columns)
return df_res
try:
df_res: df = data_frame.drop(columns=List_of_columns)
return df_res
except KeyError as ke:
raise KeyError("KeyError : " + str(ke))


def select_column(
Expand Down

0 comments on commit c07cd73

Please sign in to comment.