forked from rocketlaunchr/dataframe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
66 lines (54 loc) · 1.23 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2018-20 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved.
package dataframe
import (
"errors"
"fmt"
)
// ErrNoRows signifies that the Series, Dataframe or import data
// contains no rows of data.
var ErrNoRows = errors.New("contains no rows")
const (
// FALSE is used convert a false (bool) to an int.
FALSE = 0
// TRUE is used convert a true (bool) to an int.
TRUE = 1
)
// B converts a boolean to an int.
func B(b bool) int {
if b {
return 1
}
return 0
}
// IsValidFloat64 returns true if f is neither Nan nor ±Inf.
// Otherwise it returns false.
func IsValidFloat64(f float64) bool {
if isNaN(f) {
return false
}
if isInf(f, 0) {
return false
}
return true
}
// BoolValueFormatter is used by SetValueToStringFormatter
// to display an int as a bool. If the encountered value
// is not a 0 or 1, it will panic.
func BoolValueFormatter(v interface{}) string {
if v == nil {
return "NaN"
}
str := fmt.Sprintf("%v", v)
switch str {
case "0":
return "false"
case "1":
return "true"
default:
_ = v.(bool) // Intentionally panic
return ""
}
}
// DontLock is short-hand for various functions that permit disabling locking.
var DontLock = dontLock
var dontLock = Options{DontLock: true}