@@ -39,12 +39,20 @@ def test_encode_decode():
3939 check_encode_decode (arr , codec , precision = precision )
4040
4141
42- def test_encode ():
42+ @pytest .mark .parametrize (
43+ "offset, scale, expected" ,
44+ [
45+ (1000 , 10 , [0 , 6 , 11 , 17 , 22 , 28 , 33 , 39 , 44 , 50 ]),
46+ (1002.5 , 10 , [- 25 , - 19 , - 14 , - 8 , - 3 , 3 , 8 , 14 , 19 , 25 ]),
47+ (1000 , 0.5 , [0 , 0 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 ]),
48+ ],
49+ )
50+ def test_encode (offset : float , scale : float , expected : list [int ]):
4351 dtype = '<f8'
44- astype = '|u1'
45- codec = FixedScaleOffset (scale = 10 , offset = 1000 , dtype = dtype , astype = astype )
46- arr = np .linspace (1000 , 1001 , 10 , dtype = dtype )
47- expect = np .array ([ 0 , 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 ] , dtype = astype )
52+ astype = np . int16
53+ codec = FixedScaleOffset (scale = scale , offset = offset , dtype = dtype , astype = astype )
54+ arr = np .linspace (1000 , 1005 , 10 , dtype = dtype )
55+ expect = np .array (expected , dtype = astype )
4856 actual = codec .encode (arr )
4957 assert_array_equal (expect , actual )
5058 assert np .dtype (astype ) == actual .dtype
0 commit comments