guessformat

package
v0.0.0-...-9d3c4bc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package guessformat provides functions for making best-effort guess of the type of a TSV column.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNull

func IsNull(v string) bool

IsNull reports if the string reprents a missing value, e.g., "", "NA", "N/A".

func ParseBool

func ParseBool(v string) (value bool, ok bool)

ParseBool parses a boolean string. E.g., "true", "y", "Y" returns (true, true). A unparsable string returns (false, false).

Types

type T

type T struct {
	// contains filtered or unexported fields
}

T is used to guess the type of a column in a TSV file.

The caller creates the object T for each column in the TSV file. It then feeds the values of the column through Add() incrementally. Once Add() has an unambiguous guess of the column type, it returns one of String, Float, Int, or Bool.

func (*T) Add

func (t *T) Add(s string) Type

Add should be called with a column value found in the TSV file. It returns String,Float, or Int once it determines the column type. It returns Unknown if the type is still ambiguous.

func (*T) BestGuess

func (t *T) BestGuess() Type

BestGuess can be called any time. It returns the most probable data type given the values seen so far.

type Type

type Type uint8

Type defines possible types of a TSV column.

const (
	String Type = iota
	Float
	Int
	Bool

	// Unknown is returned by Add() when its guess is not yet finalized.
	Unknown
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL