Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
var dataForge = require('data-forge');
var E = require('linq');
//
// Create a simple data frame.
//
var values = E
.range(0, 14)
.select(function (i) {
return [i, Math.sin(i), Math.cos(i)];
})
.toArray();
var dataFrame = new dataForge.DataFrame({
columnNames: ["index", "Sin", "Cos"],
rows: values
})
.setIndex("index")
.dropSeries("index");
console.log(dataFrame.skip(4).take(5).toString());
var series = dataFrame.getSeries("Sin");
'use strict';
var dataForge = require('../../index.js');
var E = require('linq');
//
// Create a simple data frame.
//
var values = E
.range(0, 14)
.select(function (i) {
return [i, Math.sin(i), Math.cos(i)];
})
.toArray();
var dataFrame = new dataForge.DataFrame({
columnNames: ["index", "Sin", "Cos"],
rows: values
})
.setIndex("index")
.dropSeries("index");
console.log(dataFrame.skip(4).take(5).toString());
var series = dataFrame.getSeries("Sin");
return new ArrayIterator(
E.from(self.toValues())
.select(function (row, rowIndex) {
return row.concat([data[rowIndex]]);
})
.toArray()
);
},
},
index: self.getIndex(),
});
}
else {
// Replace existing column.
return new DataFrame({
columnNames: E.from(self.getColumnNames())
.select(function (thisColumnName, thisColumnIndex) {
if (thisColumnIndex === columnIndex) {
return columnName;
}
else {
return thisColumnName;
}
})
.toArray(),
rows: {
getIterator: function () {
return new ArrayIterator(
E.from(self.toValues())
.select(function (row, rowIndex) {
return E.from(row)
.select(function (column, thisColumnIndex) {
return value;
};
}
var self = this;
//todo: make this lazy.
/* todo: Want to zip here, when zip can specify the index.
series.zip(series.skip(1), function (prev, next) {
});
*/
var input = E.from(self.toPairs())
.select(function (pair) {
return {
pair: pair,
considered: false,
};
})
.toArray();
var output = [];
for (var i = 0; i < input.length; ++i) {
var underConsideration = input[i];
if (underConsideration.considered) {
// Skip this item, it has already been dealt with.
continue;
}
.then(apiSpec => {
let newApiSpec = executeInterceptor(config, apiSpec)
let defaultHost = new URI(config.url.url).host()
onLoadProgress(`Loading content from '${url}' completed`)
const apis = Enumerable
.from(newApiSpec.apis)
.select(api => {
return { path: api.path, url: config.url.resolveChildUrl(`${apiSpec.basePath}${api.path}`), onLoadProgress: onLoadProgress, config }
})
.toArray()
async.map(apis, executeFetch, (err, result) => {
if (err) {
onLoadError(`Error loading Swagger 1.x apis: ${err}`)
console.error(err)
} else {
onLoadProgress(`Loading of Swagger spec 1.x completed.`)
let apiDeclarations = {}
result.forEach(element => { apiDeclarations[element.path] = element.result })
renderAPI (apiOperations) {
if (apiOperations.length === 0 || !this.isApiVisible(apiOperations[0].apiname, apiOperations)) return
const tags = Enumerable.from(apiOperations).selectMany(o => o.spec.tags).distinct().toArray()
return (
<li>
<a href="#">
<i>
<span>
<strong>{apiOperations[0].apiname}</strong><span>
</span></span></i></a><i>
<ul>
{tags.map(tag => this.renderOperationsWithTag(apiOperations, tag))}
</ul>
</i></li><i>
)
}
</i>
getColumnNames: function () {
return E.from(self.iterable.getColumnNames())
.concat([columnName])
.distinct()
.toArray();
},
},
BaseDataFrame.prototype.setSeries = function (columnName, data) { //todo: should allow column name or index.
assert.isString(columnName, "Expected 'columnName' parameter to 'setSeries' to be a string.");
var self = this;
if (Object.isFunction(data)) {
data = E.from(self.toObjects())
.select(data)
.toArray();
}
else if (!Object.isArray(data)) {
assert.isObject(data, "Expected 'data' parameter to 'setSeries' to be either an array or a series object.");
assert.isFunction(data.reindex, "Expected 'data' parameter to 'setSeries' to have a 'reindex' function that allows the column to be reindexed.");
data = data.reindex(self.getIndex()).toValues();
}
//todo: overview and improve the way this works.
var DataFrame = require('./dataframe');
var columnIndex = self.getColumnIndex(columnName);
if (columnIndex < 0) {
var leftPairs = leftDataFrame.toPairs();
var rightPairs = rightDataFrame.toPairs();
var mergedColumnNames = [columnName]
.concat(dropElement(leftDataFrame.getColumnNames(), leftColumnIndex))
.concat(dropElement(rightDataFrame.getColumnNames(), rightColumnIndex));
var leftColumns = leftDataFrame.getColumnNames();
var rightColumns = rightDataFrame.getColumnNames();
var leftIndices = E.from(leftPairs)
.select(function (leftPair) {
return leftPair[1][leftColumns[leftColumnIndex]];
})
.toArray();
var rightIndices = E.from(rightPairs)
.select(function (rightPair) {
return rightPair[1][rightColumns[rightColumnIndex]];
})
.toArray();
var distinctIndices = E.from(leftIndices.concat(rightIndices)).distinct().toArray();
var leftMap = E.from(leftPairs)
.groupBy(function (leftPair) {
return leftPair[1][leftColumns[leftColumnIndex]];
})
.toObject(
function (group) {
return group.key();
},
function (group) {
function (row) {
return E.from(columnNames)
.select(function (columnName, columnIndex) {
return [columnName, columnIndex];
})
.toObject(
function (column) {
return column[0];
},
function (column) {
return row[column[1]];
}
);
}
);