Skip to content

Commit

Permalink
Fix Lerp panic
Browse files Browse the repository at this point in the history
  • Loading branch information
WinPooh32 committed Feb 19, 2023
1 parent 4bf6bf2 commit 7fe7fbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,15 +888,15 @@ func (d Data) Lerp() Data {

// Find first non-NaN value.
for i := 0; ; i++ {
if v := values[i]; !IsNA(v) {
beg = i
break
}
if i >= len(values) {
// All values are NaNs.
// Exit.
return d
}
if v := values[i]; !IsNA(v) {
beg = i
break
}
}

var left, right DType
Expand Down
18 changes: 18 additions & 0 deletions data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,24 @@ func TestData_Lerp(t *testing.T) {
[]DType{NaN, 2, 5, 7, 9, 11, 13.5, 16, NaN, NaN, NaN},
),
},
{
"no gaps",
fields{1, []int64{0, 1, 2, 3, 4}, []DType{0, 1, 2, 3, 4}},
MakeData(
1,
[]int64{0, 1, 2, 3, 4},
[]DType{0, 1, 2, 3, 4},
),
},
{
"all nans",
fields{1, []int64{0, 1, 2, 3, 4}, []DType{NaN, NaN, NaN, NaN, NaN}},
MakeData(
1,
[]int64{0, 1, 2, 3, 4},
[]DType{NaN, NaN, NaN, NaN, NaN},
),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 7fe7fbb

Please sign in to comment.