clallier commited on
Commit
1c4c899
·
verified ·
1 Parent(s): 97cd772

Delete download_dataset.py

Browse files
Files changed (1) hide show
  1. download_dataset.py +0 -158
download_dataset.py DELETED
@@ -1,158 +0,0 @@
1
- # /// script
2
- # dependencies = [
3
- # "pandas",
4
- # "pyarrow",
5
- # "hf",
6
- # ]
7
- # ///
8
-
9
- """Downloader script to fetch the Nesting Tasks Dataset from Zenodo."""
10
-
11
- import os
12
- import urllib.request
13
- import time
14
-
15
-
16
- def download_file(url: str, dest_path: str) -> None:
17
- """Downloads a file with clean progress printouts.
18
-
19
- Args:
20
- url (str): The direct download URL.
21
- dest_path (str): File destination path.
22
- """
23
- print(f"📥 Downloading {os.path.basename(dest_path)}...")
24
- start_time = time.time()
25
-
26
- def reporthook(count, block_size, total_size):
27
- if total_size <= 0:
28
- return
29
- current_progress = count * block_size
30
- percent = min(100, int(current_progress * 100 / total_size))
31
- # Keep progress line on same terminal line
32
- print(
33
- f"\r [{'=' * (percent // 5)}{' ' * (20 - percent // 5)}] {percent}% ({current_progress / (1024 * 1024):.1f}MB / {total_size / (1024 * 1024):.1f}MB)",
34
- end="",
35
- flush=True,
36
- )
37
-
38
- urllib.request.urlretrieve(url, dest_path, reporthook) # nosec B310
39
- duration = time.time() - start_time
40
- print(f"\n ✅ Completed in {duration:.1f}s!\n")
41
-
42
-
43
- def convert_to_parquet() -> None:
44
- """Loads gzipped pickles with pandas and saves them as modern Parquet files.
45
-
46
- Cleans up the raw .gz files afterwards to keep the repository secure and light.
47
- """
48
- import pandas as pd
49
-
50
- files = ["tasks", "parts", "constraints", "shapes"]
51
- print("============================================================")
52
- print("🔄 Converting Pickle splits to Parquet format...")
53
- print("============================================================")
54
-
55
- for name in files:
56
- pickle_file = f"{name}.gz"
57
- parquet_file = f"{name}.parquet"
58
-
59
- if not os.path.exists(pickle_file):
60
- continue
61
-
62
- print(f"⚡ Processing '{pickle_file}' -> '{parquet_file}'...")
63
- try:
64
- # 1. Read pickled dataframe
65
- df = pd.read_pickle(pickle_file)
66
-
67
- # 2. Write to Parquet (removing pandas index to keep schema clean)
68
- df.to_parquet(parquet_file, index=False)
69
- print(f" ✅ Saved {parquet_file}")
70
-
71
- # 3. Clean up the insecure raw pickle file
72
- os.remove(pickle_file)
73
- print(f" 🗑️ Removed raw {pickle_file}")
74
- except Exception as err:
75
- print(f" ❌ Failed to convert {pickle_file}: {err}")
76
- return
77
- print()
78
-
79
-
80
- def main() -> None:
81
- """Orchestrates the downloading of the Zenodo dataset files."""
82
- print("============================================================")
83
- print("📦 Zenodo Nesting Tasks Dataset Downloader")
84
- print("============================================================")
85
-
86
- # 1. Zenodo records API endpoints for version 1.1 of Lallier et al. (2022)
87
- files_to_download = {
88
- "tasks.gz": "https://zenodo.org/api/records/7030786/files/tasks.gz/content",
89
- "parts.gz": "https://zenodo.org/api/records/7030786/files/parts.gz/content",
90
- "constraints.gz": "https://zenodo.org/api/records/7030786/files/constraints.gz/content",
91
- "shapes.gz": "https://zenodo.org/api/records/7030786/files/shapes.gz/content",
92
- }
93
-
94
- # 2. Iterate and download each file directly into workspace
95
- for filename, url in files_to_download.items():
96
- # Check if either the converted parquet or the raw .gz file already exists
97
- parquet_name = filename.replace(".gz", ".parquet")
98
- if os.path.exists(parquet_name):
99
- print(
100
- f"ℹ️ File '{parquet_name}' already exists locally (converted). Skipping download.\n"
101
- )
102
- elif os.path.exists(filename):
103
- print(
104
- f"ℹ️ File '{filename}' already exists locally (raw .gz). Skipping download.\n"
105
- )
106
- else:
107
- try:
108
- download_file(url, filename)
109
- except Exception as err:
110
- print(f"❌ Failed to download {filename}: {err}")
111
- return
112
-
113
- # 3. Perform automatic conversion and cleanup
114
- convert_to_parquet()
115
-
116
- # 4. Validate and pretty-print heads of all parquet files
117
- print_dataset_head()
118
-
119
- print("============================================================")
120
- print("🎉 All dataset splits converted to Parquet successfully!")
121
- print("============================================================")
122
- print("💡 Next Step: To push this dataset to your Hugging Face profile, run:")
123
- print(" $ uv run hf upload clallier/nesting-tasks-2d . --repo-type=dataset")
124
- print("============================================================")
125
-
126
-
127
- def print_dataset_head() -> None:
128
- """Loads and pretty-prints the first 10 rows of all Parquet files to verify conversion."""
129
- import pandas as pd
130
-
131
- # Configure pandas to show all columns without wrapping or ellipsis
132
- pd.set_option("display.max_columns", None)
133
- pd.set_option("display.width", 1000)
134
-
135
- files = ["tasks", "parts", "constraints", "shapes"]
136
- print("============================================================")
137
- print("🔬 Verifying Parquet Schemas (First 10 rows of each split)")
138
- print("============================================================")
139
-
140
- for name in files:
141
- parquet_file = f"{name}.parquet"
142
- if not os.path.exists(parquet_file):
143
- print(f"⚠️ Warning: '{parquet_file}' not found for validation.\n")
144
- continue
145
-
146
- print(f"\n📄 Split: {parquet_file}")
147
- print("------------------------------------------------------------")
148
- try:
149
- df = pd.read_parquet(parquet_file)
150
- print(df.head(10))
151
- except Exception as err:
152
- print(f"❌ Failed to read {parquet_file}: {err}")
153
- print("------------------------------------------------------------")
154
- print()
155
-
156
-
157
- if __name__ == "__main__":
158
- main()