""" Dataset loading script for github-top-projects with multiple configurations """ import csv import datasets _CITATION = """\ @dataset{github_trending_2013_2025, title={GitHub Trending Projects Dataset (2013-2025)}, author={Ronan Takizawa}, year={2025}, publisher={Hugging Face}, url={https://huggingface.co/datasets/ronantakizawa/github-top-projects} } """ _DESCRIPTION = """\ A comprehensive dataset of 423,098 GitHub trending repository entries spanning 12+ years (August 2013 - November 2025). This dataset has two configurations: - 'full': Complete daily trending data (423,098 entries) - 'monthly': Top 25 repositories per month with weighted scoring (3,200 entries) """ _HOMEPAGE = "https://huggingface.co/datasets/ronantakizawa/github-top-projects" _LICENSE = "MIT" _URLS = { "full": "github-trending-projects-full.csv", "monthly": "github-top-projects-by-month.csv", } class GitHubTopProjectsConfig(datasets.BuilderConfig): """BuilderConfig for GitHubTopProjects.""" def __init__(self, **kwargs): """BuilderConfig for GitHubTopProjects. Args: **kwargs: keyword arguments forwarded to super. """ super(GitHubTopProjectsConfig, self).__init__(**kwargs) class GitHubTopProjects(datasets.GeneratorBasedBuilder): """GitHub Trending Projects Dataset""" BUILDER_CONFIGS = [ GitHubTopProjectsConfig( name="full", version=datasets.Version("1.0.0"), description="Complete daily trending data (423,098 entries)", ), GitHubTopProjectsConfig( name="monthly", version=datasets.Version("1.0.0"), description="Top 25 repositories per month with weighted scoring (3,200 entries)", ), ] DEFAULT_CONFIG_NAME = "full" def _info(self): if self.config.name == "full": features = datasets.Features( { "name": datasets.Value("string"), "star_count": datasets.Value("int64"), "fork_count": datasets.Value("int64"), "repo_owner": datasets.Value("string"), "rank": datasets.Value("int64"), "date": datasets.Value("string"), } ) else: # monthly features = datasets.Features( { "month": datasets.Value("string"), "rank": datasets.Value("int64"), "repository": datasets.Value("string"), "repo_owner": datasets.Value("string"), "repo_name": datasets.Value("string"), "star_count": datasets.Value("int64"), "fork_count": datasets.Value("int64"), "ranking_appearances": datasets.Value("int64"), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): urls = _URLS[self.config.name] data_file = dl_manager.download_and_extract(urls) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "filepath": data_file, }, ), ] def _generate_examples(self, filepath): """Yields examples.""" with open(filepath, encoding="utf-8") as f: reader = csv.DictReader(f) for idx, row in enumerate(reader): if self.config.name == "full": yield idx, { "name": row["name"], "star_count": int(row["star_count"]) if row["star_count"] else 0, "fork_count": int(row["fork_count"]) if row["fork_count"] else 0, "repo_owner": row["repo_owner"], "rank": int(row["rank"]) if row["rank"] else 0, "date": row["date"], } else: # monthly yield idx, { "month": row["month"], "rank": int(row["rank"]), "repository": row["repository"], "repo_owner": row["repo_owner"], "repo_name": row["repo_name"], "star_count": int(row["star_count"]) if row["star_count"] else 0, "fork_count": int(row["fork_count"]) if row["fork_count"] else 0, "ranking_appearances": int(row["ranking_appearances"]), }