|
11 | 11 | import statistics as s |
12 | 12 | from pathlib import Path |
13 | 13 |
|
14 | | -import pandas as pd |
15 | | -import pydp as dp # our privacy library |
| 14 | +import pandas as pd # type: ignore |
| 15 | +import pydp as dp # this library |
16 | 16 | from pydp.algorithms.laplacian import BoundedSum, BoundedMean, Count, Max |
17 | 17 |
|
18 | | -# Creating a class ClassReporter |
19 | | - |
| 18 | +from typing import Union |
20 | 19 |
|
| 20 | +# Creating a class ClassReporter |
21 | 21 | class CarrotReporter: |
22 | 22 |
|
23 | 23 | # Function to read the csv file and creating a dataframe |
@@ -62,14 +62,16 @@ def private_mean(self, privacy_budget: float) -> float: |
62 | 62 | return x.quick_result(list(self._df["carrots_eaten"])) |
63 | 63 |
|
64 | 64 | # Function to return the DP count of the number of animals who ate more than "limit" carrots. |
65 | | - def private_count_above(self, privacy_budget: float, limit: int) -> int: |
| 65 | + def private_count_above( |
| 66 | + self, privacy_budget: float, limit: int |
| 67 | + ) -> Union[int, float]: |
66 | 68 | x = Count(privacy_budget, dtype="int") |
67 | 69 | return x.quick_result( |
68 | 70 | list(self._df[self._df.carrots_eaten > limit]["carrots_eaten"]) |
69 | 71 | ) |
70 | 72 |
|
71 | 73 | # Function to return the DP maximum of the number of carrots eaten by any one animal. |
72 | | - def private_max(self, privacy_budget: float) -> int: |
| 74 | + def private_max(self, privacy_budget: float) -> Union[int, float]: |
73 | 75 | # 0 and 150 are the upper and lower limits for the search bound. |
74 | 76 | x = Max(privacy_budget, 0, 150, dtype="int") |
75 | 77 | return x.quick_result(list(self._df["carrots_eaten"])) |
|
0 commit comments