|
1 | | -import { data } from "@tensorflow/tfjs"; |
| 1 | +import * as tf from "@tensorflow/tfjs"; |
2 | 2 | import fetch from "node-fetch"; |
3 | 3 | import XLSX from "xlsx"; |
4 | | -import { open, Dataset, isDataset } from "frictionless.js"; |
5 | | -import toArray from "stream-to-array"; |
6 | 4 | import { Utils } from "../core/utils"; |
7 | 5 | import { DataFrame } from "../core/frame"; |
8 | 6 |
|
@@ -32,7 +30,7 @@ export const read_csv = async (source, chunk) => { |
32 | 30 | } |
33 | 31 |
|
34 | 32 | let data = []; |
35 | | - const csvDataset = data.csv(source); |
| 33 | + const csvDataset = tf.data.csv(source); |
36 | 34 | const column_names = await csvDataset.columnNames(); |
37 | 35 | const sample = csvDataset.take(chunk); |
38 | 36 | await sample.forEachAsync((row) => data.push(Object.values(row))); |
@@ -155,64 +153,3 @@ export const read_excel = async (kwargs) => { |
155 | 153 | throw new Error(err); |
156 | 154 | } |
157 | 155 | }; |
158 | | - |
159 | | -/** |
160 | | - * Opens a file using frictionless.js specification. |
161 | | - * @param {string} pathOrDescriptor A path to the file/resources. It can be a local file, |
162 | | - * a URL to a tabular data (CSV, EXCEL) or Datahub.io Data Resource. |
163 | | - * Data comes with extra properties and specification conforming to the Frictionless Data standards. |
164 | | - * @param {object} configs { data_num (Defaults => 0): The specific dataset to load, when reading data from a datapackage.json, |
165 | | - * header (Defaults => true): Whether the dataset contains header or not. |
166 | | - * } |
167 | | - * @returns {DataFrame} Danfo DataFrame/Series |
168 | | - */ |
169 | | -export const read = async ( |
170 | | - path_or_descriptor, |
171 | | - configs = { data_num: 0, header: true } |
172 | | -) => { |
173 | | - let data_num = configs["data_num"]; |
174 | | - let header = configs["header"]; |
175 | | - let rows, file; |
176 | | - |
177 | | - if (isDataset(path_or_descriptor)) { |
178 | | - console.log( |
179 | | - "datapackage.json found. Loading Dataset package from Datahub.io" |
180 | | - ); |
181 | | - const dataset = await Dataset.load(path_or_descriptor); |
182 | | - file = dataset.resources[data_num]; |
183 | | - //TODO: toArray does not work in browser env, so this feature breaks when build for the web. |
184 | | - // To fix this, we need a function to convert stream into text |
185 | | - rows = await toArray(await file.rows()); |
186 | | - } else { |
187 | | - try { |
188 | | - file = open(path_or_descriptor); |
189 | | - rows = await toArray(await file.rows()); |
190 | | - } catch (error) { |
191 | | - console.log(error); |
192 | | - } |
193 | | - } |
194 | | - |
195 | | - if ([ "csv", "xls", "xlsx" ].includes(await file.descriptor.format)) { |
196 | | - if (header) { |
197 | | - let df = new DataFrame(rows.slice(1), { columns: rows[0] }); |
198 | | - return df; |
199 | | - } else { |
200 | | - let df = new DataFrame(rows); |
201 | | - return df; |
202 | | - } |
203 | | - } else { |
204 | | - let df = new DataFrame(rows); |
205 | | - return df; |
206 | | - } |
207 | | -}; |
208 | | - |
209 | | -// /** |
210 | | -// * Reads a Database into DataFrame |
211 | | -// * |
212 | | -// * @param {source} URL or local file path to retreive JSON file. |
213 | | -// * @returns {Promise} DataFrame structure of parsed CSV data |
214 | | -// */ |
215 | | -// export const read_sql = async (source) => { |
216 | | - |
217 | | -// return "TODO" |
218 | | -// } |
0 commit comments