// NewFromCSV creates a new Frame from CSV.
// Pass 'nil' header if first row is used as header strings.
// Pass 'non-nil' header if the data starts from the first row, without header strings.
356146
func NewFromCSV(header []string, fpath string) (Frame, error) {
	f, err := openToRead(fpath)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	rd := csv.NewReader(f)

	// FieldsPerRecord is the number of expected fields per record.
	// If FieldsPerRecord is positive, Read requires each record to
	// have the given number of fields. If FieldsPerRecord is 0, Read sets it to
	// the number of fields in the first record, so that future records must
	// have the same field count. If FieldsPerRecord is negative, no check is
	// made and records may have a variable number of fields.
	rd.FieldsPerRecord = -1

	rows, err := rd.ReadAll()
	if err != nil {
		return nil, err
	}

	return NewFromRows(header, rows)
}
311613
func (ccpack *CDSPackage) InitFromBuffer(buf []byte) (*ChaincodeData, error) {
	//incase ccpack is reused
	ccpack.reset()

	depSpec := &pb.ChaincodeDeploymentSpec{}
	err := proto.Unmarshal(buf, depSpec)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal deployment spec from bytes")
	}

	databytes, id, data, err := ccpack.getCDSData(depSpec)
	if err != nil {
		return nil, err
	}

	ccpack.buf = buf
	ccpack.depSpec = depSpec
	ccpack.data = data
	ccpack.datab = databytes
	ccpack.id = id

	return ccpack.GetChaincodeData(), nil
}
623277
func NewDefaultLlvBarsForStreamWithSrcLen(sourceLength uint, priceStream gotrade.DOHLCVStreamSubscriber) (indicator *LlvBars, err error) {
	ind, err := NewDefaultLlvBarsWithSrcLen(sourceLength)
	priceStream.AddTickSubscription(ind)
	return ind, err
}
757785
func NewCSVStorage(rw io.ReadWriter) (Storage, error) {
	cs := &csvStorage{
		w:     csv.NewWriter(rw),
		cache: NewMemoryStorage(),
	}
	if err := readCSV(cs.cache, rw); err != nil {
		return nil, err
	}
	return cs, nil
}
480681
func NewDefaultLlvForStreamWithSrcLen(sourceLength uint, priceStream gotrade.DOHLCVStreamSubscriber) (indicator *Llv, err error) {
	ind, err := NewDefaultLlvWithSrcLen(sourceLength)
	priceStream.AddTickSubscription(ind)
	return ind, err
}
765523
func CreateFrom(chartfile *chart.Metadata, dest string, src string) error {
	schart, err := Load(src)
	if err != nil {
		return fmt.Errorf("could not load %s: %s", src, err)
	}

	schart.Metadata = chartfile

	var updatedTemplates []*chart.Template

	for _, template := range schart.Templates {
		newData := Transform(string(template.Data), "<CHARTNAME>", schart.Metadata.Name)
		updatedTemplates = append(updatedTemplates, &chart.Template{Name: template.Name, Data: newData})
	}

	schart.Templates = updatedTemplates
	if schart.Values != nil {
		schart.Values = &chart.Config{Raw: string(Transform(schart.Values.Raw, "<CHARTNAME>", schart.Metadata.Name))}
	}
	return SaveDir(schart, dest)
}
452100
func (s *InputSerialization) SetCsv(v *CSVInput) *InputSerialization {
	s.Csv = v
	return s
}
179526
func (yamlFramer) NewFrameReader(r io.ReadCloser) io.ReadCloser {
	// extract the YAML document chunks directly
	return utilyaml.NewDocumentDecoder(r)
}
412498
func NewBufferFrom(p []byte) *Buffer {
	buf := NewBuffer(len(p))
	buf.Write(p)
	zero(p, len(p))
	return buf
}
1359648
func (g *GcsFS) NewObject(objectname string) (cloudstorage.Object, error) {
	obj, err := g.Get(context.Background(), objectname)
	if err != nil && err != cloudstorage.ErrObjectNotFound {
		return nil, err
	} else if obj != nil {
		return nil, cloudstorage.ErrObjectExists
	}

	cf := cloudstorage.CachePathObj(g.cachepath, objectname, g.Id)

	return &object{
		name:       objectname,
		metadata:   map[string]string{cloudstorage.ContentTypeKey: cloudstorage.ContentType(objectname)},
		gcsb:       g.gcsb(),
		bucket:     g.bucket,
		cachedcopy: nil,
		cachepath:  cf,
	}, nil
}
783157
func NewFrom(from interface{}, opts ...Option) (*Config, error) {
	c := New()
	if err := c.Merge(from, opts...); err != nil {
		return nil, err
	}
	return c, nil
}
696613
func NewFrame(pc uintptr, file string, line int) Frame {
	fn := runtime.FuncForPC(pc)
	if fn == nil {
		return Frame{}
	}
	pack, name := parseFunctionName(fn.Name())
	return Frame{
		Line:     line,
		File:     filepath.Base(file),
		Package:  pack,
		Function: name,
	}
}
474584
func (pr Properties) MarshallCSV() (string, error) {
	buf := new(bytes.Buffer)
	w := csv.NewWriter(buf)
	if err := w.Write(pr.Header); err != nil {
		return buf.String(), err
	}
	for _, line := range pr.DataFrame {
		if err := w.Write(line); err != nil {
			return buf.String(), err
		}
	}
	w.Flush()

	return buf.String(), nil
}
312713
func newObjectFromType(t raml.Type, name string) object {
	obj := newObject(name, t.Description, t.Properties)
	obj.T = t
	obj.handleAdvancedType()
	return obj
}
820628
func NewTableDataFileCSV(path string, comma rune, stripBom bool) (table.TableData, error) {
	tbl := table.NewTableData()
	csvReader, f, err := NewReader(path, comma, stripBom)
	if err != nil {
		return tbl, err
	}
	defer f.Close()
	if DebugReadCSV {
		i := -1
		for {
			line, err := csvReader.Read()
			if err == io.EOF {
				break
			} else if err != nil {
				return tbl, err
			}
			i += 1
			if i == 0 {
				tbl.Columns = line
				continue
			}
			tbl.Records = append(tbl.Records, line)
			if i > 2500 {
				fmt.Printf("[%v] %v\n", i, strings.Join(line, ","))
			}
		}

	} else {
		lines, err := csvReader.ReadAll()
		if err != nil {
			return tbl, err
		}
		tbl.LoadMergedRows(lines)
	}
	return tbl, nil
}
896896
func NewCsvSource(table string, indexCol int, ior io.Reader, exit <-chan bool) (*CsvDataSource, error) {

	m := CsvDataSource{table: table, indexCol: indexCol}
	if rc, ok := ior.(io.ReadCloser); ok {
		m.rc = rc
	}

	buf := bufio.NewReader(ior)

	first2, err := buf.Peek(2)
	if err != nil {
		u.Errorf("Error opening bufio.peek for csv reader %v", err)
		return nil, err
	}

	// TODO:  move this compression to the file-reader not here
	if err == nil && len(first2) == 2 && bytes.Equal(first2, []byte{'\x1F', '\x8B'}) {
		gr, err := gzip.NewReader(buf)
		if err != nil {
			u.Errorf("Could not open reader? %v", err)
			return nil, err
		}
		m.gz = gr
		m.csvr = csv.NewReader(gr)
	} else {
		m.csvr = csv.NewReader(buf)
	}

	m.csvr.TrailingComma = true // allow empty fields
	// if flagCsvDelimiter == "|" {
	// 	m.csvr.Comma = '|'
	// } else if flagCsvDelimiter == "\t" || flagCsvDelimiter == "t" {
	// 	m.csvr.Comma = '\t'
	// }
	headers, err := m.csvr.Read()
	if err != nil {
		u.Warnf("err csv %v", err)
		return nil, err
	}
	//u.Debugf("headers: %v", headers)
	m.headers = headers
	m.colindex = make(map[string]int, len(headers))
	for i, key := range headers {
		key = strings.ToLower(key)
		m.colindex[key] = i
		m.headers[i] = key
	}
	m.loadTable()
	//u.Infof("csv headers: %v colIndex: %v", headers, m.colindex)
	return &m, nil
}
353034
func NewRow(columns ...uint64) *Row {
	r := &Row{}
	for _, i := range columns {
		r.SetBit(i)
	}
	return r
}