Coverage for /pythoncovmergedfiles/medio/medio/src/fuzz_interpolate.py: 69%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1###### Coverage stub
2import atexit
3import coverage
4cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
5cov.start()
6# Register an exist handler that will print coverage
7def exit_handler():
8 cov.stop()
9 cov.save()
10atexit.register(exit_handler)
11####### End of coverage stub
12#!/usr/bin/python3
13# Copyright 2023 Google LLC
14#
15# Licensed under the Apache License, Version 2.0 (the "License");
16# you may not use this file except in compliance with the License.
17# You may obtain a copy of the License at
18#
19# http://www.apache.org/licenses/LICENSE-2.0
20#
21# Unless required by applicable law or agreed to in writing, software
22# distributed under the License is distributed on an "AS IS" BASIS,
23# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24# See the License for the specific language governing permissions and
25# limitations under the License.
26"""Fuzzes the pandas interpolate function, generating and manipulating DataFrames with various data types to uncover
27potential edge cases."""
29import sys
30import atheris
31import pandas as pd
34def TestOneInput(data):
35 fdp = atheris.FuzzedDataProvider(data)
37 try:
38 rows = fdp.ConsumeIntInRange(1, 15)
39 num_rows = fdp.ConsumeIntInRange(3, 20)
40 num_columns = fdp.ConsumeIntInRange(3, 20)
41 col_names = [fdp.ConsumeString(fdp.ConsumeIntInRange(1, 15)) for _ in range(num_columns)]
43 df_content = {}
44 for col_name in col_names:
45 if fdp.ConsumeBool():
46 df_content[col_name] = [fdp.ConsumeInt(10) for _ in range(num_rows)]
47 elif fdp.ConsumeBool():
48 df_content[col_name] = [fdp.ConsumeString(10) for _ in range(num_rows)]
49 elif fdp.ConsumeBool():
50 df_content[col_name] = [fdp.ConsumeIntInRange(0, 2100) for _ in range(num_rows)]
51 elif fdp.ConsumeBool():
52 df_content[col_name] = [fdp.ConsumeFloat() for _ in range(num_rows)]
53 else:
54 df_content[col_name] = [fdp.ConsumeBool() for _ in range(num_rows)]
56 df = pd.DataFrame(df_content)
58 # Fuzz interpolate options
59 method = fdp.PickValueInList(
60 ['linear', 'time', 'index', 'values', 'nearest', 'zero', 'slinear', 'quadratic',
61 'cubic', 'barycentric', 'krogh', 'polynomial', 'spline', 'bessel', 'holistic', 'akima',
62 fdp.ConsumeString(15)])
63 axis = fdp.PickValueInList([0, 1, 'index', 'columns'])
64 limit = fdp.ConsumeIntInRange(1, rows) if fdp.ConsumeBool() else None
65 inplace = fdp.ConsumeBool()
66 limit_direction = fdp.PickValueInList(['forward', 'backward', 'both', None])
67 limit_area = fdp.PickValueInList([None, 'inside', 'outside'])
68 order = fdp.ConsumeIntInRange(1, 5) if method == 'polynomial' else None
69 s = fdp.ConsumeFloatInRange(0, 1) if method == 'spline' else None
70 robust = fdp.ConsumeBool()
72 df.interpolate(
73 method=method,
74 axis=axis,
75 limit=limit,
76 inplace=inplace,
77 limit_direction=limit_direction,
78 limit_area=limit_area,
79 order=order,
80 s=s,
81 robust=robust
82 )
84 except (
85 ValueError # If method argument is invalid
86 ):
87 pass
90def main():
91 atheris.Setup(sys.argv, TestOneInput)
92 atheris.instrument_all()
93 atheris.Fuzz()
96if __name__ == "__main__":
97 main()