Datasets:

Modalities:
Text
Formats:
arrow
Languages:
English
ArXiv:
Libraries:
Datasets
License:
AnnaWegmann commited on
Commit
b888fcb
·
verified ·
1 Parent(s): a519e21

Update dataset.py

Browse files
Files changed (1) hide show
  1. 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
- table = pa.ipc.RecordBatchFileReader(filepath).read_all()
 
 
 
 
71
  data = table.to_pydict()
72
- keys = list(data.keys())
73
- for i in range(len(data[keys[0]])):
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)