change csv dataset constructor

This commit is contained in:
Arkadiusz Kondas 2016-04-16 21:26:58 +02:00
parent a4ab370a48
commit dea6972305

View File

@ -26,8 +26,10 @@ class CsvDataset extends ArrayDataset
throw DatasetException::missingFile(basename($filepath));
}
if(false === $handle = fopen($filepath, 'r')) {
throw DatasetException::cantOpenFile(basename($filepath));
}
$row = 0;
if (($handle = fopen($filepath, 'r')) !== false) {
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
++$row;
if ($headingRow && $row == 1) {
@ -37,8 +39,6 @@ class CsvDataset extends ArrayDataset
$this->labels[] = $data[$features];
}
fclose($handle);
} else {
throw DatasetException::cantOpenFile(basename($filepath));
}
}
}