Skip to content

Commit 6c2261d

Browse files
committed
[GitHub Action] Lint and format code with Ruff
1 parent 8c7e3e0 commit 6c2261d

File tree

4 files changed

+9
-32
lines changed

4 files changed

+9
-32
lines changed

examples/spaceship-titanic/baseline.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ def predict(test: Path, save: Path):
66
# TODO: Add a model here
77

88
test_data = pd.read_csv(test)
9-
submission = pd.DataFrame(
10-
{"PassengerId": test_data["PassengerId"], "Transported": False}
11-
)
9+
submission = pd.DataFrame({"PassengerId": test_data["PassengerId"], "Transported": False})
1210
submission.to_csv(save, index=False)
1311
print(f"Test submission saved to {save}")
1412

examples/spaceship-titanic/evaluate.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,14 @@ class InvalidSubmissionError(Exception):
1212
pass
1313

1414

15-
def prepare_for_accuracy_metric(
16-
submission: pd.DataFrame,
17-
answers: pd.DataFrame,
18-
target_column: str,
19-
id_column: str,
20-
) -> dict:
21-
15+
def prepare_for_accuracy_metric(submission: pd.DataFrame, answers: pd.DataFrame, target_column: str, id_column: str) -> dict:
2216
# Answers checks
23-
assert (
24-
target_column in answers.columns
25-
), f"Answers must have a `{target_column}` column"
17+
assert target_column in answers.columns, f"Answers must have a `{target_column}` column"
2618
assert id_column in answers.columns, f"Answers must have a `{id_column}` column"
2719

2820
# Submission checks
2921
if len(submission) != len(answers):
30-
raise InvalidSubmissionError(
31-
"Submission must have the same length as the answers."
32-
)
22+
raise InvalidSubmissionError("Submission must have the same length as the answers.")
3323
if target_column not in submission.columns:
3424
raise InvalidSubmissionError(f"Submission must have a `{target_column}` column")
3525
if id_column not in submission.columns:
@@ -40,9 +30,7 @@ def prepare_for_accuracy_metric(
4030
answers = answers.sort_values(id_column)
4131

4232
if (submission[id_column].values != answers[id_column].values).any():
43-
raise InvalidSubmissionError(
44-
f"Submission and Answers `{id_column}`'s do not match"
45-
)
33+
raise InvalidSubmissionError(f"Submission and Answers `{id_column}`'s do not match")
4634

4735
y_pred = submission[target_column].to_numpy()
4836
y_true = answers[target_column].to_numpy()
@@ -52,10 +40,7 @@ def prepare_for_accuracy_metric(
5240

5341
def grade(submission: pd.DataFrame, answers: pd.DataFrame) -> float:
5442
accuracy_inputs = prepare_for_accuracy_metric(
55-
submission=submission,
56-
answers=answers,
57-
target_column="Transported",
58-
id_column="PassengerId",
43+
submission=submission, answers=answers, target_column="Transported", id_column="PassengerId"
5944
)
6045
return accuracy_score(**accuracy_inputs)
6146

@@ -70,9 +55,7 @@ def grade(submission: pd.DataFrame, answers: pd.DataFrame) -> float:
7055

7156
# Check if files exist before proceeding
7257
if not answers_path.exists():
73-
print(
74-
f"Error: Answers file not found at {answers_path}"
75-
) # Updated path in error message
58+
print(f"Error: Answers file not found at {answers_path}") # Updated path in error message
7659
sys.exit(1)
7760

7861
if not submission_path.exists():

examples/spaceship-titanic/optimize.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ def predict(test: Path, save: Path):
66
# TODO: Add a model here
77

88
test_data = pd.read_csv(test)
9-
submission = pd.DataFrame(
10-
{"PassengerId": test_data["PassengerId"], "Transported": False}
11-
)
9+
submission = pd.DataFrame({"PassengerId": test_data["PassengerId"], "Transported": False})
1210
submission.to_csv(save, index=False)
1311
print(f"Test submission saved to {save}")
1412

examples/spaceship-titanic/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ def split_data(public: Path, private: Path):
3232
new_test.to_csv(private / "test.csv", index=False)
3333
print("test sample shape:", new_test.shape)
3434
print(f"Validation data saved to {public / 'test.csv'}")
35-
new_test.drop("Transported", axis="columns").to_csv(
36-
public / "test.csv", index=False
37-
)
35+
new_test.drop("Transported", axis="columns").to_csv(public / "test.csv", index=False)
3836

3937
# remove the previous files
4038
os.remove("train.csv")

0 commit comments

Comments
 (0)