lalababa commited on
Commit
6e1cd54
·
verified ·
1 Parent(s): 56b8a57

Delete time_series_library.py

Browse files
Files changed (1) hide show
  1. time_series_library.py +0 -90
time_series_library.py DELETED
@@ -1,90 +0,0 @@
1
- # time_series_library.py
2
- print("[TSL] custom script loaded")
3
- import os, pandas as pd
4
- from datasets import (
5
- GeneratorBasedBuilder, Split, SplitGenerator, Features, Value
6
- )
7
-
8
- class TimeSeriesLibrary(GeneratorBasedBuilder):
9
- print("[TSL] custom script loaded")
10
- BUILDER_CONFIGS = []
11
-
12
- def _info(self):
13
- import pandas as pd
14
- from datasets import Features, Value
15
- df = pd.read_csv(
16
- list(self.config.data_files.values())[0]
17
- if isinstance(self.config.data_files, dict)
18
- else self.config.data_files[0],
19
- nrows=10
20
- )
21
- cols = {}
22
- for c in df.columns:
23
- cols[c] = Value("string") if df[c].dtype == object else Value("float64")
24
- return self.dataset_info_from_configs(features=Features(cols))
25
-
26
-
27
- from datasets import Split, SplitGenerator
28
-
29
- def _split_generators(self, dl_manager):
30
- print("use spilt")
31
- dfiles = self.config.data_files
32
- files = list(dfiles) if isinstance(dfiles, (list, tuple)) else [dfiles]
33
-
34
- gens = []
35
-
36
- def split_name_for(path, used):
37
- """按文件名自动判别 split;若重复则加后缀避免合并"""
38
- name = os.path.basename(str(path)).lower()
39
- if "train" in name:
40
- base = "train"
41
- elif any(k in name for k in ["val", "valid", "validation"]):
42
- base = "validation"
43
- elif "test_label" in name or "label" in name:
44
- base = "test_label"
45
- elif "test" in name:
46
- base = "test"
47
- else:
48
- # 没有关键字就用文件名(去掉拓展名)
49
- base = os.path.splitext(os.path.basename(str(path)))[0]
50
-
51
- # 避免同名冲突:train/train_1/train_2...
52
- s = base
53
- idx = 1
54
- while s in used:
55
- s = f"{base}_{idx}"
56
- idx += 1
57
- used.add(s)
58
- return s
59
-
60
- used_names = set()
61
- for f in files:
62
- sname = split_name_for(f, used_names)
63
- # 标准 split 用内置常量;自定义用 Split(sname)
64
- if sname == "train":
65
- gens.append(SplitGenerator(name=Split.TRAIN, gen_kwargs={"filepath": f}))
66
- elif sname == "validation":
67
- gens.append(SplitGenerator(name=Split.VALIDATION, gen_kwargs={"filepath": f}))
68
- elif sname == "test":
69
- gens.append(SplitGenerator(name=Split.TEST, gen_kwargs={"filepath": f}))
70
- else:
71
- gens.append(SplitGenerator(name=Split(sname), gen_kwargs={"filepath": f}))
72
-
73
- # 如果列表为空(极端情况),兜底把所有文件各自做一个 split
74
- if not gens:
75
- for i, f in enumerate(files):
76
- gens.append(SplitGenerator(name=Split(f"file_{i}"), gen_kwargs={"filepath": f}))
77
-
78
- return gens
79
-
80
-
81
-
82
- def _generate_examples(self, filepath, row_slice=None):
83
- if isinstance(filepath, (list, tuple)):
84
- filepath = filepath[0]
85
- df = pd.read_csv(filepath)
86
- if row_slice:
87
- a, b = row_slice
88
- df = df.iloc[a:b]
89
- for i, row in df.iterrows():
90
- yield i, row.to_dict()