tables.md

May 8, 2024 ยท View on GitHub

Home > @datashaper/tables

tables package

Functions

FunctionDescription
applyCodebook(table, codebook, strategy, dataTableSchema)
coerce(value, dataType)Ensure an incoming value matches its datatype. For example, if user input is from a textfield, parse it.
columnIndexesWithZeros(table)Returns a list of column indices that contain at least one 0.
columnNamesWithZeros(table)Returns a list of column names that contain at least one 0.
columnType(table, column)
columnTypes(table, columns)Generates column typings info for a table.
container(id, table, metadata)
determineType(value)Guess the type of a table value with more discernment than typeof https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
enumValidator(field, includeIndexes)Constructs a function that validates a column against the enum constraint.
fixedBinCount(column, min, max, count, clamped, format)Bins column values using a fixed number of bins. The standard behavior here is to truncate a numeric value to the lower bound of its bin range. This keeps the output numerical but loses information about specific bin boundaries. Because binning is a conversion from continuous to categorical, many use cases prefer an output value that displays the range. The format parameter here will produce a printed string as output.
fixedBinStep(column, min, max, step, clamped, format)Bins column values using a fixed bin width. The number of resulting bins is therefore variable. The standard behavior here is to truncate a numeric value to the lower bound of its bin range. This keeps the output numerical but loses information about specific bin boundaries. Because binning is a conversion from continuous to categorical, many use cases prefer an output value that displays the range. The format parameter here will produce a printed string as output.
format(value, options)Returns a nice formatted string for a number
formatIfNumber(value)Returns a formatted string for a number, otherwise returns the original value
formatNumberStr(value, options)Formats a string using specified numeric parser options, so that it is ready for standard numeric parsing. (i.e., default js impl is to consider '.' a decimal). If the string has invalid construction to be a number, an empty string will be returned, which will be parsed as NaN. We do this because parseInt does not recognize the thousands separator, but if we remove them all even in invalid cases (e.g., '1,00'), invalid numbers could be parsed downstream as valid. The same occurs with decimal separators: parseFloat will ignore anything after the first.
fromCSV(text, options)Drop-in replacement for arquero fromCSV, using our internal parsing with auto-typing turned on. Meant for quick-and-dirty reads, with the advantage that our default parsing aligns with pandas. Use readTable for more control over schema options and formats.
generateCodebook(table, typeHints, options)
getDate(value)
getters(table)Returns a map of all of the column getters for a table.
guessDataType(options)Factory function to provide a type guessing function for any string value. This uses optional type hints to account for string values such as boolean and null formats.
guessDelimiter(text, config)
introspect(table, detailed, columns)Performs type inference and stats on a table/columns.
isArray(delimiter, format)Detect if a string is an array by looking for the delimiter. It's expected that in a CSV any array cells will be quoted. Also note that if the default delimiter, comma, is used, these may be detected as valid numbers if checked first.
isBoolean(falseValues, trueValues)
isDate(value)
isNull(naValues)
isNullOrUndefined(naValues)
isNumber(decimal, thousands)
isObject(value)
isValidNumber(value)
loadCSV(url, options)Drop-in replacement for arquero loadCSV, using our internal parsing with auto-typing turned on. Meant for quick-and-dirty reads, with the advantage that our default parsing aligns with pandas. Use readTable for more control over schema options and formats.
maximumValidator(field, includeIndexes)Constructs a function that validates a column against the maximum constraint.
maxLengthValidator(field, includeIndexes)Constructs a function that validates a column against the maxLength constraint.
minimumValidator(field, includeIndexes)Constructs a function that validates a column against the minimum constraint.
minLengthValidator(field, includeIndexes)Constructs a function that validates a column against the minLength constraint.
parseArray(subtype, delimiter, options)
parseAs(type, hints, subtype)Factory function to create a value parser based on defined data type and type hints
parseBoolean(naValues, trueValues, falseValues)
parseDate(naValues)
parseNumber(naValues, decimal, thousands)
parseObject(options)
parseString(naValues)
parseUndefined(naValues)
patternValidator(field, includeIndexes)Constructs a function that validates a column against the pattern constraint.
readTable(input, schema, options)Read an input table
requiredValidator(field, includeIndexes)Constructs a function that validates a column against the required constraint.
rows(table, options)Returns a table's rows as a two-dimensional array.
sliceTable(table, offset, limit)Safely applies slicing args to a table
stats(table, columns)Generates detailed column stats for a table.
typeGuesserFactory(options)
unapplyCodebook(table, codebook, strategy, dataTableSchema)
uniqueValidator(field, includeIndexes)Constructs a function that validates a column against the unique constraint.
validateColumn(table, field, includeIndexes)Validates a column against a Field definition's constraints.
validateTable(table, codebook, includeIndexes)Validates an entire table against a codebook's Field constraints.

Interfaces

InterfaceDescription
ReadTableOptions
RowsOptions
TableContainer
TableMetadata