Skip to content

Commit 7dbf3c0

Browse files
committed
Fix static analysis issues in arxiv_category_converter.py - formatting and line length
1 parent 587e2e0 commit 7dbf3c0

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

dev/arxiv_category_converter.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,71 @@
33
ArXiv category code to user-friendly name converter.
44
Called by arxiv_fetch.py to convert category codes to readable names.
55
"""
6+
# Standard library
67
import csv
78
import os
9+
10+
# Third-party
811
import yaml
912

13+
1014
def load_category_mapping(data_dir):
1115
"""Load category code to label mapping from YAML file."""
1216
mapping_file = os.path.join(data_dir, "arxiv_category_map.yaml")
13-
17+
1418
if not os.path.exists(mapping_file):
1519
return {}
16-
20+
1721
try:
18-
with open(mapping_file, 'r') as f:
22+
with open(mapping_file, "r") as f:
1923
return yaml.safe_load(f) or {}
2024
except Exception:
2125
return {}
2226

27+
2328
def convert_categories_to_friendly_names(input_file, output_file, data_dir):
2429
"""
2530
Convert category codes in CSV to user-friendly names.
26-
31+
2732
Args:
2833
input_file: Path to input CSV with category codes
2934
output_file: Path to output CSV with friendly names
3035
data_dir: Directory containing arxiv_category_map.yaml
3136
"""
3237
if not os.path.exists(input_file):
3338
return
34-
39+
3540
# Load category mapping
3641
category_mapping = load_category_mapping(data_dir)
37-
38-
with open(input_file, 'r') as infile, open(output_file, 'w', newline='') as outfile:
42+
43+
with (
44+
open(input_file, "r") as infile,
45+
open(output_file, "w", newline="") as outfile,
46+
):
3947
reader = csv.DictReader(infile)
40-
48+
4149
# Create new fieldnames with both code and label
4250
fieldnames = []
4351
for field in reader.fieldnames:
4452
fieldnames.append(field)
45-
if field == 'CATEGORY':
46-
fieldnames.append('CATEGORY_LABEL')
47-
48-
writer = csv.DictWriter(outfile, fieldnames=fieldnames, dialect='unix')
53+
if field == "CATEGORY":
54+
fieldnames.append("CATEGORY_LABEL")
55+
56+
writer = csv.DictWriter(outfile, fieldnames=fieldnames, dialect="unix")
4957
writer.writeheader()
50-
58+
5159
for row in reader:
52-
if 'CATEGORY' in row:
53-
category_code = row['CATEGORY']
54-
# Convert code to label, fallback to uppercase first part if not found
60+
if "CATEGORY" in row:
61+
category_code = row["CATEGORY"]
62+
# Convert code to label, fallback to uppercase first part
5563
category_label = category_mapping.get(
5664
category_code,
57-
category_code.split('.')[0].upper() if category_code and '.' in category_code else category_code
65+
(
66+
category_code.split(".")[0].upper()
67+
if category_code and "." in category_code
68+
else category_code
69+
),
5870
)
59-
row['CATEGORY_LABEL'] = category_label
60-
71+
row["CATEGORY_LABEL"] = category_label
72+
6173
writer.writerow(row)

0 commit comments

Comments
 (0)