Skip to content

Commit

Permalink
Removing panic from fileType (go-gota#89)
Browse files Browse the repository at this point in the history
Removing panic from fileType, so the default type will be used, rather then stopping the program
  • Loading branch information
kellrott authored and danicat committed Apr 2, 2019
1 parent faf470e commit e9ca46f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,4 @@ This project adheres to [Semantic Versioning](http://semver.org/).
[0.6.0]:https://github.com/kniren/gota/compare/v0.5.0...v0.6.0
[0.7.0]:https://github.com/kniren/gota/compare/v0.6.0...v0.7.0
[0.8.0]:https://github.com/kniren/gota/compare/v0.7.0...v0.8.0
[0.9.0]:https://github.com/kniren/gota/compare/v0.8.0...v0.9.0
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ mean := func(s series.Series) series.Series {
}
return series.Floats(sum / float64(len(floats)))
}
df.Cbind(mean)
df.Rbind(mean)
df.Capply(mean)
df.Rapply(mean)
```

#### Chaining operations
Expand Down
24 changes: 13 additions & 11 deletions dataframe/dataframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"unicode/utf8"

"github.com/kniren/gota/series"
"github.com/go-gota/gota/series"
)

// DataFrame is a data structure designed for operating on table like data (Such
Expand Down Expand Up @@ -962,10 +962,12 @@ func LoadRecords(records [][]string, options ...LoadOption) DataFrame {

t, ok := cfg.types[colname]
if !ok {
t = cfg.defaultType
if cfg.detectTypes {
t = findType(rawcol)
}
t = cfg.defaultType
if cfg.detectTypes {
if l, err := findType(rawcol); err != nil {
t = l
}
}
}
types[i] = t
}
Expand Down Expand Up @@ -1831,7 +1833,7 @@ func parseSelectIndexes(l int, indexes SelectIndexes, colnames []string) ([]int,
return idx, nil
}

func findType(arr []string) series.Type {
func findType(arr []string) (series.Type, error) {
var hasFloats, hasInts, hasBools, hasStrings bool
for _, str := range arr {
if str == "" || str == "NaN" {
Expand All @@ -1853,15 +1855,15 @@ func findType(arr []string) series.Type {
}
switch {
case hasStrings:
return series.String
return series.String, nil
case hasBools:
return series.Bool
return series.Bool, nil
case hasFloats:
return series.Float
return series.Float, nil
case hasInts:
return series.Int
return series.Int, nil
default:
panic("couldn't detect type")
return series.String, fmt.Errorf("couldn't detect type")
}
}

Expand Down
20 changes: 10 additions & 10 deletions series/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"math"

"github.com/gonum/stat"
"gonum.org/v1/gonum/stat"
)

// Series is a data structure designed for operating on arrays of elements that
Expand Down Expand Up @@ -92,12 +92,12 @@ type Comparator string
// Supported Comparators
const (
Eq Comparator = "==" // Equal
Neq = "!=" // Non equal
Greater = ">" // Greater than
GreaterEq = ">=" // Greater or equal than
Less = "<" // Lesser than
LessEq = "<=" // Lesser or equal than
In = "in" // Inside
Neq Comparator = "!=" // Non equal
Greater Comparator = ">" // Greater than
GreaterEq Comparator = ">=" // Greater or equal than
Less Comparator = "<" // Lesser than
LessEq Comparator = "<=" // Lesser or equal than
In Comparator = "in" // Inside
)

// Type is a convenience alias that can be used for a more type safe way of
Expand All @@ -107,9 +107,9 @@ type Type string
// Supported Series Types
const (
String Type = "string"
Int = "int"
Float = "float"
Bool = "bool"
Int Type = "int"
Float Type = "float"
Bool Type = "bool"
)

// Indexes represent the elements that can be used for selecting a subset of
Expand Down

0 comments on commit e9ca46f

Please sign in to comment.