Spaces:
Sleeping
Sleeping
yuki.tsutsumi
commited on
Commit
•
5e72c46
1
Parent(s):
31ce9a1
[update]mypyのエラー解消。
Browse files- .gitignore +1 -1
- requirements.txt +1 -0
- src/aws/s3.py +4 -4
- src/forms/change_request.py +5 -4
.gitignore
CHANGED
@@ -162,7 +162,7 @@ cython_debug/
|
|
162 |
|
163 |
.DS_Store
|
164 |
|
165 |
-
#
|
166 |
data/change_request_history.csv
|
167 |
data/output.docx
|
168 |
data/output_deviation.docx
|
|
|
162 |
|
163 |
.DS_Store
|
164 |
|
165 |
+
# 申請履歴/申請書/報告書はリポジトリにはアップロードしない。
|
166 |
data/change_request_history.csv
|
167 |
data/output.docx
|
168 |
data/output_deviation.docx
|
requirements.txt
CHANGED
@@ -13,3 +13,4 @@ boto3 == 1.34.131
|
|
13 |
pandas-stubs == 2.2.2.240603
|
14 |
boto3-stubs == 1.34.149
|
15 |
botocore == 1.34.155
|
|
|
|
13 |
pandas-stubs == 2.2.2.240603
|
14 |
boto3-stubs == 1.34.149
|
15 |
botocore == 1.34.155
|
16 |
+
mypy-boto3-s3 == 1.34.158
|
src/aws/s3.py
CHANGED
@@ -2,8 +2,8 @@ from io import StringIO
|
|
2 |
|
3 |
import boto3
|
4 |
import pandas as pd
|
5 |
-
from botocore.client import BaseClient
|
6 |
from botocore.exceptions import NoCredentialsError, PartialCredentialsError
|
|
|
7 |
|
8 |
from src.utils import setup_logger
|
9 |
|
@@ -15,12 +15,12 @@ csv_extension = ".csv"
|
|
15 |
err_msg_file_is_not_csv = "指定したファイルはcsvではありません。"
|
16 |
|
17 |
|
18 |
-
def get_client() ->
|
19 |
return boto3.client("s3")
|
20 |
|
21 |
|
22 |
def get_csv_as_pd_dataframe_from_s3(
|
23 |
-
client:
|
24 |
) -> pd.DataFrame:
|
25 |
if not file_name.lower().endswith(csv_extension):
|
26 |
raise ValueError(err_msg_file_is_not_csv)
|
@@ -43,7 +43,7 @@ def get_csv_as_pd_dataframe_from_s3(
|
|
43 |
|
44 |
|
45 |
def save_pd_dataframe_as_csv_to_s3(
|
46 |
-
client:
|
47 |
) -> None:
|
48 |
if not file_name.lower().endswith(csv_extension):
|
49 |
raise ValueError(err_msg_file_is_not_csv)
|
|
|
2 |
|
3 |
import boto3
|
4 |
import pandas as pd
|
|
|
5 |
from botocore.exceptions import NoCredentialsError, PartialCredentialsError
|
6 |
+
from mypy_boto3_s3.client import S3Client
|
7 |
|
8 |
from src.utils import setup_logger
|
9 |
|
|
|
15 |
err_msg_file_is_not_csv = "指定したファイルはcsvではありません。"
|
16 |
|
17 |
|
18 |
+
def get_client() -> S3Client:
|
19 |
return boto3.client("s3")
|
20 |
|
21 |
|
22 |
def get_csv_as_pd_dataframe_from_s3(
|
23 |
+
client: S3Client, bucket_name: str, file_name: str
|
24 |
) -> pd.DataFrame:
|
25 |
if not file_name.lower().endswith(csv_extension):
|
26 |
raise ValueError(err_msg_file_is_not_csv)
|
|
|
43 |
|
44 |
|
45 |
def save_pd_dataframe_as_csv_to_s3(
|
46 |
+
client: S3Client, data: pd.DataFrame, bucket_name: str, file_name: str
|
47 |
) -> None:
|
48 |
if not file_name.lower().endswith(csv_extension):
|
49 |
raise ValueError(err_msg_file_is_not_csv)
|
src/forms/change_request.py
CHANGED
@@ -603,13 +603,13 @@ def save_change_request_history(
|
|
603 |
except s3_client.exceptions.NoSuchKey:
|
604 |
df = pd.DataFrame()
|
605 |
|
606 |
-
|
607 |
question_answer_headers = generate_question_answer_headers(questions)
|
608 |
-
|
609 |
|
610 |
existing_headers = df.columns.tolist()
|
611 |
new_columns = [
|
612 |
-
header for header in
|
613 |
]
|
614 |
|
615 |
for column in new_columns:
|
@@ -632,6 +632,7 @@ def save_change_request_history(
|
|
632 |
new_row = pd.DataFrame([new_row_data])
|
633 |
df = pd.concat([df, new_row], ignore_index=True)
|
634 |
|
|
|
635 |
save_pd_dataframe_as_csv_to_s3(
|
636 |
s3_client,
|
637 |
df,
|
@@ -640,7 +641,7 @@ def save_change_request_history(
|
|
640 |
)
|
641 |
|
642 |
|
643 |
-
def
|
644 |
new_headers = [
|
645 |
"申請者",
|
646 |
"備考",
|
|
|
603 |
except s3_client.exceptions.NoSuchKey:
|
604 |
df = pd.DataFrame()
|
605 |
|
606 |
+
new_common_header = generate_common_header()
|
607 |
question_answer_headers = generate_question_answer_headers(questions)
|
608 |
+
new_common_header.extend(question_answer_headers)
|
609 |
|
610 |
existing_headers = df.columns.tolist()
|
611 |
new_columns = [
|
612 |
+
header for header in new_common_header if header not in existing_headers
|
613 |
]
|
614 |
|
615 |
for column in new_columns:
|
|
|
632 |
new_row = pd.DataFrame([new_row_data])
|
633 |
df = pd.concat([df, new_row], ignore_index=True)
|
634 |
|
635 |
+
# NOTE: トライアル版のため、排他制御は実施しない。バケットはバージョニングする。
|
636 |
save_pd_dataframe_as_csv_to_s3(
|
637 |
s3_client,
|
638 |
df,
|
|
|
641 |
)
|
642 |
|
643 |
|
644 |
+
def generate_common_header() -> List[str]:
|
645 |
new_headers = [
|
646 |
"申請者",
|
647 |
"備考",
|