Files
NexQuant/rdagent/scenarios/data_science/example/source_data/playground-series-s4e9/prepare.py
T
TPTBusiness 732361bb90 fix(security): resolve path-injection, B701, B101, B112 Bandit alerts
- Path injection (B614): centralized safe_resolve_path in core/utils.py,
  refactored 6 UI modules to use it with safe_root validation
- B701: added explicit autoescape=select_autoescape() to Jinja2
  Environment() calls in 3 files
- B101: replaced assert statements with proper if/raise patterns in
  12+ files (partial)
- B112: added logger.warning() to bare except:continue blocks in
  5 files
2026-05-01 13:42:59 +02:00

44 lines
1.5 KiB
Python

from pathlib import Path
import pandas as pd
from sklearn.model_selection import train_test_split
def prepare(raw: Path, public: Path, private: Path):
# Create train and test splits from train set
old_train = pd.read_csv(raw / "train.csv")
new_train, new_test = train_test_split(old_train, test_size=0.1, random_state=0)
# Create sample submission
sample_submission = new_test.copy()
sample_submission["price"] = 43878.016
sample_submission.drop(sample_submission.columns.difference(["id", "price"]), axis=1, inplace=True)
sample_submission.to_csv(public / "sample_submission.csv", index=False)
# Create private files
new_test.to_csv(private / "submission_test.csv", index=False)
# Create public files visible to agents
new_train.to_csv(public / "train.csv", index=False)
new_test.drop(["price"], axis=1, inplace=True)
new_test.to_csv(public / "test.csv", index=False)
# Checks
if new_test.shape[1] != 12:
raise AssertionError("Public test set should have 12 columns")
if new_train.shape[1] != 13:
raise AssertionError("Public train set should have 13 columns")
if len(new_train) + len(new_test) != len(old_train):
raise AssertionError("Length of new_train and new_test should equal length of old_train")
if __name__ == "__main__":
competitions = "playground-series-s4e9"
raw = Path(__file__).resolve().parent
prepare(
raw=raw,
public=raw.parent.parent / competitions,
private=raw.parent.parent / "eval" / competitions,
)