Skip to content

Commit

Permalink
Revisit fix for go-gota#169 - just don't treat 'NA' as a nil-like value
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamthapar committed Nov 20, 2024
1 parent a7d1a6c commit 7be9a58
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions dataframe/dataframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ func LoadStructs(i interface{}, options ...LoadOption) DataFrame {
defaultType: series.String,
detectTypes: true,
hasHeader: true,
nanValues: []string{"NA", "NaN", "<nil>"},
nanValues: []string{"NaN", "<nil>"},
}

// Set any custom load options
Expand Down Expand Up @@ -1185,7 +1185,7 @@ func LoadRecords(records [][]string, options ...LoadOption) DataFrame {
defaultType: series.String,
detectTypes: true,
hasHeader: true,
nanValues: []string{"NA", "NaN", "<nil>"},
nanValues: []string{"NaN", "<nil>"},
}

// Set any custom load options
Expand Down Expand Up @@ -1219,22 +1219,17 @@ func LoadRecords(records [][]string, options ...LoadOption) DataFrame {
types := make([]series.Type, len(headers))
rawcols := make([][]string, len(headers))
for i, colname := range headers {
t, useCustomType := cfg.types[colname]
rawcol := make([]string, len(records))
for j := 0; j < len(records); j++ {
rawcol[j] = records[j][i]
if useCustomType && t == series.String {
// skip the convertion when using custom string type
continue
}
if findInStringSlice(rawcol[j], cfg.nanValues) != -1 {
rawcol[j] = "NaN"
}
}
rawcols[i] = rawcol

// try to auto detect the data type
if !useCustomType {
t, ok := cfg.types[colname]
if !ok {
t = cfg.defaultType
if cfg.detectTypes {
if l, err := findType(rawcol); err == nil {
Expand Down

0 comments on commit 7be9a58

Please sign in to comment.