Skip to content

Commit

Permalink
fix: Improve JSDoc comments and typings. (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
jheer committed May 20, 2021
1 parent 29e9ed5 commit 378ab3a
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/arrow/arrow-column.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const isList = id => id === Type.List || id === Type.FixedSizeList;
/**
* Create an Arquero column that proxies access to an Arrow column.
* @param {object} arrow An Apache Arrow column.
* @return {import('./column').ColumnType} An Arquero-compatible column.
* @return {import('../table/column').ColumnType} An Arquero-compatible column.
*/
export default function arrowColumn(arrow, nested) {
if (arrow.dictionary) return arrowDictionary(arrow);
Expand Down
2 changes: 2 additions & 0 deletions src/arrow/encode/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Table } from 'apache-arrow'; // eslint-disable-line no-unused-vars

import dataFromObjects from './data-from-objects';
import dataFromTable from './data-from-table';
import { scanArray, scanTable } from './scan';
Expand Down
2 changes: 1 addition & 1 deletion src/format/from-arrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ColumnTable from '../table/column-table';
* Create a new table backed by an Apache Arrow table instance.
* @param {object} arrow An Apache Arrow data table or byte buffer.
* @param {ArrowOptions} options Options for Arrow import.
* @param {ColumnTable} table A new table containing the imported values.
* @return {ColumnTable} A new table containing the imported values.
*/
export default function(arrow, options = {}) {
arrow = from(arrow);
Expand Down
4 changes: 3 additions & 1 deletion src/format/from-csv.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ColumnTable from '../table/column-table'; // eslint-disable-line no-unused-vars

import fromTextRows from './from-text-rows';
import parseDelimited from './parse/parse-delimited';

Expand Down Expand Up @@ -33,7 +35,7 @@ import parseDelimited from './parse/parse-delimited';
* of input column values, use the parse option.
* @param {string} text A string in a delimited-value format.
* @param {CSVParseOptions} options The formatting options.
* @param {ColumnTable} table A new table containing the parsed values.
* @return {ColumnTable} A new table containing the parsed values.
*/
export default function(text, options = {}) {
const next = parseDelimited(text, options);
Expand Down
4 changes: 3 additions & 1 deletion src/format/from-fixed.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ColumnTable from '../table/column-table'; // eslint-disable-line no-unused-vars

import fromTextRows from './from-text-rows';
import parseLines from './parse/parse-lines';
import error from '../util/error';
Expand Down Expand Up @@ -32,7 +34,7 @@ import error from '../util/error';
* parsing of input column values, use the parse option.
* @param {string} text A string in a fixed-width file format.
* @param {FixedParseOptions} options The formatting options.
* @param {import('../table/column-table')} table A new table containing the parsed values.
* @return {ColumnTable} A new table containing the parsed values.
*/
export default function(text, options = {}) {
const read = parseLines(text, options);
Expand Down
2 changes: 1 addition & 1 deletion src/format/from-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import isString from '../util/is-string';
* metadata such as a "fields" array of ordered column information.
* @param {string|object} data A string in JSON format, or pre-parsed object.
* @param {JSONParseOptions} options The formatting options.
* @param {ColumnTable} table A new table containing the parsed values.
* @return {ColumnTable} A new table containing the parsed values.
*/
export default function(json, options = {}) {
const autoType = defaultTrue(options.autoType);
Expand Down
9 changes: 3 additions & 6 deletions src/format/load-file.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ColumnTable from '../table/column-table'; // eslint-disable-line no-unused-vars

import fromArrow from './from-arrow';
import fromCSV from './from-csv';
import fromFixed from './from-fixed';
Expand Down Expand Up @@ -111,9 +113,4 @@ export function loadJSON(path, options) {

function parseJSON(data, options) {
return isArray(data) ? from(data) : fromJSON(data, options);
}

/**
* An Arquero Column Table
* @typedef {import('../table/column-table')} ColumnTable
*/
}
9 changes: 3 additions & 6 deletions src/format/load-url.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ColumnTable from '../table/column-table'; // eslint-disable-line no-unused-vars

import fromArrow from './from-arrow';
import fromCSV from './from-csv';
import fromFixed from './from-fixed';
Expand Down Expand Up @@ -86,9 +88,4 @@ export function loadJSON(url, options) {

function parseJSON(data, options) {
return isArray(data) ? from(data) : fromJSON(data, options);
}

/**
* An Arquero Column Table
* @typedef {import('../table/column-table')} ColumnTable
*/
}
2 changes: 2 additions & 0 deletions src/format/to-csv.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ColumnTable from '../table/column-table'; // eslint-disable-line no-unused-vars

import { columns, scan } from './util';
import { formatUTCDate } from '../util/format-date';
import isDate from '../util/is-date';
Expand Down
2 changes: 2 additions & 0 deletions src/format/to-html.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ColumnTable from '../table/column-table'; // eslint-disable-line no-unused-vars

import formatValue from './value';
import { columns, formats, scan } from './util';
import isFunction from '../util/is-function';
Expand Down
2 changes: 2 additions & 0 deletions src/format/to-json.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ColumnTable from '../table/column-table'; // eslint-disable-line no-unused-vars

import { columns } from './util';
import { formatUTCDate } from '../util/format-date';
import defaultTrue from '../util/default-true';
Expand Down
2 changes: 2 additions & 0 deletions src/format/to-markdown.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ColumnTable from '../table/column-table'; // eslint-disable-line no-unused-vars

import formatValue from './value';
import { columns, formats, scan } from './util';

Expand Down
7 changes: 2 additions & 5 deletions src/format/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import Table from '../table/table'; // eslint-disable-line no-unused-vars

import inferFormat from './infer';
import isFunction from '../util/is-function';

/**
* Data table.
* @typedef {typeof import('../table/table')} Table
*/

/**
* Column selection function.
* @typedef {(table: Table) => string[]} ColumnSelectFunction
Expand Down
7 changes: 1 addition & 6 deletions src/op/op-api.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import functions from './functions';
import op from './op';

/**
* Table expression operation.
* @typedef {import('./op').Op} Op
*/
import op, { Op } from './op'; // eslint-disable-line no-unused-vars

export const any = (field) => op('any', field);
export const count = () => op('count');
Expand Down
2 changes: 1 addition & 1 deletion src/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export default class Table extends Transformable {

/**
* Proxy type for BitSet class.
* @typedef {typeof import('./bit-set')} BitSet
* @typedef {import('./bit-set').default} BitSet
*/

/**
Expand Down
26 changes: 18 additions & 8 deletions src/table/transformable.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class Transformable {
* The resulting table provides a filtered view over the original data; no
* data copy is made. To create a table that copies only filtered data to
* new data structures, call {@link Transformable#reify} on the output table.
* @param {TableExpr|string} criteria Filter criteria as a table expression.
* @param {TableExpr} criteria Filter criteria as a table expression.
* Both aggregate and window functions are permitted, taking into account
* {@link Transformable#groupby} or {@link Transformable#orderby} settings.
* @return {this} A new table with filtered rows.
Expand Down Expand Up @@ -741,12 +741,22 @@ export default class Transformable {

/**
* A function defined over a table row.
* @typedef {(d?: object, $?: Params) => any} TableExpr
* @typedef {(d?: object, $?: Params) => any} TableExprFunc
*/

/**
* A table expression defined over a single table.
* @typedef {TableExprFunc|TableExprString} TableExpr
*/

/**
* A function defined over rows from two tables.
* @typedef {(a?: object, b?: object, $?: Params) => any} TableExpr2
* @typedef {(a?: object, b?: object, $?: Params) => any} TableFunc2
*/

/**
* A table expression defined over two tables.
* @typedef {TableExprFunc2|TableExprString} TableExpr2
*/

/**
Expand Down Expand Up @@ -775,12 +785,12 @@ export default class Transformable {

/**
* An object of column name / table expression pairs.
* @typedef {{ [name: string]: (TableExpr | TableExprString) }} ExprObject
* @typedef {{ [name: string]: TableExpr }} ExprObject
*/

/**
* An object of column name / two-table expression pairs.
* @typedef {{ [name: string]: (TableExpr2 | TableExprString) }} Expr2Object
* @typedef {{ [name: string]: TableExpr2 }} Expr2Object
*/

/**
Expand Down Expand Up @@ -820,7 +830,7 @@ export default class Transformable {

/**
* Column values to use as a join key.
* @typedef {ColumnRef|TableExpr} JoinKey
* @typedef {ColumnRef|TableExprFunc} JoinKey
*/

/**
Expand All @@ -830,7 +840,7 @@ export default class Transformable {

/**
* A predicate specification for joining two tables.
* @typedef {JoinKeys|TableExpr2|null} JoinPredicate
* @typedef {JoinKeys|TableExprFunc2|null} JoinPredicate
*/

/**
Expand Down Expand Up @@ -889,7 +899,7 @@ export default class Transformable {
* @typedef {object} SampleOptions
* @property {boolean} [replace=false] Flag for sampling with replacement.
* @property {boolean} [shuffle=true] Flag to ensure randomly ordered rows.
* @property {string|TableExpr} [weight] Column values to use as weights
* @property {string|TableExprFunc} [weight] Column values to use as weights
* for sampling. Rows will be sampled with probability proportional to
* their relative weight. The input should be a column name string or
* a table expression compatible with {@link Transformable#derive}.
Expand Down
6 changes: 4 additions & 2 deletions src/verbs/helpers/agg.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Table from '../../table/table'; // eslint-disable-line no-unused-vars

/**
* Convenience function for computing a single aggregate value for
* a table. Equivalent to ungrouping a table, applying a rollup verb
* for a single aggregate, and extracting the resulting value.
* @param {import('../../table/Table')} table A table instance.
* @param {import('../../table/Transformable').TableExpr|string} expr An
* @param {Table} table A table instance.
* @param {import('../../table/Transformable').TableExpr} expr An
* aggregate table expression to evaluate.
* @return {import('../../table/Table').DataValue} The aggregate value.
* @example agg(table, op.max('colA'))
Expand Down

0 comments on commit 378ab3a

Please sign in to comment.