Coverage for cvx/simulator/utils/interpolation.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.6.8, created at 2025-01-10 14:11 +0000

1# Copyright 2023 Stanford University Convex Optimization Group 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15 

16def interpolate(ts): 

17 """interpolate""" 

18 first = ts.first_valid_index() 

19 last = ts.last_valid_index() 

20 

21 ts.loc[first:last] = ts.loc[first:last].ffill() 

22 return ts 

23 

24 

25def valid(ts): 

26 # check the two series are identical 

27 return (ts.dropna().index).equals(interpolate(ts).dropna().index)