hollyyfc commited on
Commit
3699533
·
1 Parent(s): b93d2dc

fix data script

Browse files
Files changed (1) hide show
  1. tidytuesday_script.py +0 -133
tidytuesday_script.py DELETED
@@ -1,133 +0,0 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- import csv
17
- import json
18
- import os
19
- from typing import List
20
- import datasets
21
- import logging
22
-
23
-
24
- # Find for instance the citation on arxiv or on the dataset repo/website
25
- _CITATION = """\
26
- @InProceedings{huggingface:dataset,
27
- title = {TidyTuesday for Python},
28
- author={Holly Cui
29
- },
30
- year={2024}
31
- }
32
- """
33
-
34
-
35
- _DESCRIPTION = """\
36
- This dataset compiles TidyTuesday datasets from 2023-2024, aiming to make resources in the R community more accessible for Python users.
37
- """
38
-
39
-
40
- _HOMEPAGE = "https://github.com/hollyyfc/tidytuesday-for-python.git"
41
-
42
-
43
- _LICENSE = ""
44
-
45
-
46
- _URLS = {
47
- "train": "https://github.com/hollyyfc/tidytuesday-for-python/blob/135b835de4373e04a43027d2cbedc5643f5c54ef/tidytuesday_train_json.json",
48
- # https://raw.githubusercontent.com/hollyyfc/tidytuesday-for-python/main/tidytuesday_train_json.json
49
- "validation": "https://github.com/hollyyfc/tidytuesday-for-python/blob/135b835de4373e04a43027d2cbedc5643f5c54ef/tidytuesday_val_json.json",
50
- # https://raw.githubusercontent.com/hollyyfc/tidytuesday-for-python/main/tidytuesday_val_json.json
51
- }
52
-
53
-
54
- class TidyTuesdayPython(datasets.GeneratorBasedBuilder):
55
-
56
- _URLS = _URLS
57
- VERSION = datasets.Version("1.1.0")
58
-
59
-
60
- def _info(self):
61
-
62
- return datasets.DatasetInfo(
63
- description=_DESCRIPTION,
64
- features=datasets.Features(
65
- {
66
- "date_posted": datasets.Value("string"),
67
- "project_name": datasets.Value("string"),
68
- "project_source": datasets.features.Sequence(datasets.Value("string")),
69
- "description": datasets.Value("string"),
70
- "data_source_url": datasets.Value("string"),
71
- "data_dictionary": datasets.features.Sequence(
72
- {
73
- "variable": datasets.Value("string"),
74
- "class": datasets.Value("string"),
75
- "description": datasets.Value("string"),
76
- }
77
- ),
78
- "data": datasets.features.Sequence(
79
- {
80
- "file_name": datasets.Value("string"),
81
- "url": datasets.Value("string"),
82
- }
83
- ),
84
- "data_load": datasets.features.Sequence(
85
- {
86
- "file_name": datasets.Value("string"),
87
- "load_url": datasets.Value("string"),
88
- }
89
- ),
90
- }
91
- ),
92
- # No default supervised_keys (as we have to pass both premise
93
- supervised_keys=None,
94
- # Homepage of the dataset for documentation
95
- homepage=_HOMEPAGE,
96
- # Citation for the dataset
97
- citation=_CITATION,
98
- )
99
-
100
- def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
101
- urls_to_download = self._URLS
102
- downloaded_files = dl_manager.download_and_extract(urls_to_download)
103
- return [
104
- datasets.SplitGenerator(
105
- name=datasets.Split.TRAIN,
106
- gen_kwargs={
107
- "filepath": downloaded_files["train"]
108
- }
109
- ),
110
- datasets.SplitGenerator(
111
- name=datasets.Split.VALIDATION,
112
- gen_kwargs={
113
- "filepath": downloaded_files["validation"]
114
- }
115
- ),
116
- ]
117
-
118
- # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
119
- def _generate_examples(self, filepath):
120
- logging.info("generating examples from = %s", filepath)
121
- with open(filepath, "r") as j:
122
- tidytuesday_json = json.loads(j.read())
123
- for record in tidytuesday_json:
124
- id_ = record['date_posted']
125
- yield id_, {
126
- "project_name": record["project_name"],
127
- "project_source": record["project_source"],
128
- "description": record["description"],
129
- "data_source_url": record["data_source_url"],
130
- "data_dictionary": record["data_dictionary"],
131
- "data": record["data"],
132
- "data_load": record["data_load"],
133
- }