-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiples of duration, like pandas
This change means that you can specify the unit of a bin-size that's a multiple of a duration. So instead of a unit like `minute`, you can divide it by multiples of a minute, e.g. `10minute` causing the data to be divided into 10-minute sized bins.
- Loading branch information
1 parent
dbaa984
commit c638509
Showing
2 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package tbin | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseSpec(t *testing.T) { | ||
type tcase struct { | ||
Spec string | ||
ExpMult int64 | ||
ExpDelt int64 | ||
ExpErr error | ||
} | ||
|
||
for idx, test := range []tcase{ | ||
{ | ||
Spec: "30D", | ||
ExpMult: 30, | ||
ExpDelt: TD_1_day, | ||
ExpErr: nil, | ||
}, | ||
{ | ||
Spec: "30m", | ||
ExpMult: 30, | ||
ExpDelt: TD_1_min, | ||
ExpErr: nil, | ||
}, | ||
{ | ||
Spec: "5Y", | ||
ExpMult: 5, | ||
ExpDelt: TD_1_day * 365, | ||
ExpErr: nil, | ||
}, | ||
{ | ||
Spec: "1W", | ||
ExpMult: 1, | ||
ExpDelt: TD_1_week, | ||
ExpErr: nil, | ||
}, | ||
{ | ||
Spec: "m", | ||
ExpMult: 1, | ||
ExpDelt: TD_1_min, | ||
ExpErr: nil, | ||
}, | ||
{ | ||
Spec: "1", | ||
ExpMult: 0, | ||
ExpDelt: 0, | ||
ExpErr: fmt.Errorf("no timedelta configured for abbreviation of \"\""), | ||
}, | ||
} { | ||
mult, delt, err := ParseSpec(test.Spec) | ||
require.Equal(t, test.ExpErr, err, "for test #%d", idx) | ||
require.Equal(t, test.ExpMult, mult, "for test #%d", idx) | ||
require.Equal(t, test.ExpDelt, delt, "for test #%d", idx) | ||
} | ||
} |