Skip to content

Commit 2a06143

Browse files
committed
Remove frictionless read method
1 parent f9867c7 commit 2a06143

2 files changed

Lines changed: 5 additions & 67 deletions

File tree

danfojs/src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import NDframe from "./core/generic";
33
export { Series } from "./core/series";
44
export { DataFrame } from "./core/frame";
55
export { to_datetime } from "./core/timeseries";
6-
export { read_csv, read_json, read_excel, read } from "./io/reader";
6+
export { read_csv, read_json, read_excel } from "./io/reader";
77
export { merge } from "./core/merge";
88
export { concat } from "./core/concat";
99
export { LabelEncoder, OneHotEncoder } from "./preprocessing/encodings";
@@ -14,5 +14,6 @@ export { Configs } from "./config/config";
1414
export { NDframe };
1515
export { Str } from "./core/strings";
1616
export { Utils } from "./core/utils";
17+
export * as tf from "@tensorflow/tfjs";
1718

18-
export const _version = "0.2.3";
19+
export const _version = "0.2.2";

danfojs/src/io/reader.js

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { data } from "@tensorflow/tfjs";
1+
import * as tf from "@tensorflow/tfjs";
22
import fetch from "node-fetch";
33
import XLSX from "xlsx";
4-
import { open, Dataset, isDataset } from "frictionless.js";
5-
import toArray from "stream-to-array";
64
import { Utils } from "../core/utils";
75
import { DataFrame } from "../core/frame";
86

@@ -32,7 +30,7 @@ export const read_csv = async (source, chunk) => {
3230
}
3331

3432
let data = [];
35-
const csvDataset = data.csv(source);
33+
const csvDataset = tf.data.csv(source);
3634
const column_names = await csvDataset.columnNames();
3735
const sample = csvDataset.take(chunk);
3836
await sample.forEachAsync((row) => data.push(Object.values(row)));
@@ -155,64 +153,3 @@ export const read_excel = async (kwargs) => {
155153
throw new Error(err);
156154
}
157155
};
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

Comments
 (0)