Datasets:
Update dataset.py
Browse files- dataset.py +7 -4
dataset.py
CHANGED
|
@@ -67,11 +67,14 @@ class MyDataset(GeneratorBasedBuilder):
|
|
| 67 |
|
| 68 |
def _generate_examples(self, filepath):
|
| 69 |
if filepath.endswith(".arrow"):
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
data = table.to_pydict()
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
yield i, {k: data[k][i] for k in keys}
|
| 75 |
elif filepath.endswith(".csv"):
|
| 76 |
with open(filepath, encoding="utf-8") as f:
|
| 77 |
reader = csv.DictReader(f)
|
|
|
|
| 67 |
|
| 68 |
def _generate_examples(self, filepath):
|
| 69 |
if filepath.endswith(".arrow"):
|
| 70 |
+
try:
|
| 71 |
+
with open(filepath, "rb") as f:
|
| 72 |
+
table = pa.ipc.RecordBatchFileReader(f).read_all()
|
| 73 |
+
except pa.lib.ArrowInvalid:
|
| 74 |
+
raise ValueError(f"File {filepath} is not a valid Arrow file.")
|
| 75 |
data = table.to_pydict()
|
| 76 |
+
for i in range(len(next(iter(data.values())))):
|
| 77 |
+
yield i, {k: data[k][i] for k in data}
|
|
|
|
| 78 |
elif filepath.endswith(".csv"):
|
| 79 |
with open(filepath, encoding="utf-8") as f:
|
| 80 |
reader = csv.DictReader(f)
|