Skip to content

Commit 7062da2

Browse files
Added mypy support (#308)
* added mypy support * added mypy test in ci * added mypy installation * Update tests.yml * piepnv compatibility
1 parent 550bc93 commit 7062da2

File tree

11 files changed

+26
-17
lines changed

11 files changed

+26
-17
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ jobs:
7777
make check-coverage-python
7878
env:
7979
MIN_COVERAGE: 80
80+
- name: Mypy test
81+
run: |
82+
pipenv install mypy
83+
pipenv run mypy tests/ pydp/
84+
pipenv run mypy examples/carrots_demo examples/restaurant_demo
85+
8086
# Need to see how to run the c++ code coverage
8187
# - name: Check C++ code coverage
8288
# if: runner.os == 'Linux' # Coverage will be the same on all systems so only running the check on Linux

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ sphinx = "*"
1313
sphinx-rtd-theme = "*"
1414
gcovr = "*"
1515
coverage = "*"
16+
mypy = "*"
1617

1718
[packages]
1819
jupyter = "*"

examples/carrots_demo/carrots.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
import statistics as s
1212
from pathlib import Path
1313

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
1616
from pydp.algorithms.laplacian import BoundedSum, BoundedMean, Count, Max
1717

18-
# Creating a class ClassReporter
19-
18+
from typing import Union
2019

20+
# Creating a class ClassReporter
2121
class CarrotReporter:
2222

2323
# Function to read the csv file and creating a dataframe
@@ -62,14 +62,16 @@ def private_mean(self, privacy_budget: float) -> float:
6262
return x.quick_result(list(self._df["carrots_eaten"]))
6363

6464
# 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]:
6668
x = Count(privacy_budget, dtype="int")
6769
return x.quick_result(
6870
list(self._df[self._df.carrots_eaten > limit]["carrots_eaten"])
6971
)
7072

7173
# 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]:
7375
# 0 and 150 are the upper and lower limits for the search bound.
7476
x = Max(privacy_budget, 0, 150, dtype="int")
7577
return x.quick_result(list(self._df["carrots_eaten"]))

examples/restaurant_demo/restaurant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import math
55
import statistics as s
6-
import pandas as pd
6+
import pandas as pd # type: ignore
77
from collections import defaultdict
88

99
# Assumptions:

pydp/algorithms/_algorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import math
22

3-
from .._pydp import _algorithms
3+
from .._pydp import _algorithms # type: ignore
44

55
from typing import Union, List
66

pydp/algorithms/laplacian/_percentile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ def percentile(self) -> float:
2828
"""
2929
percentile Gets the value that was set in the constructor.
3030
"""
31-
return self._MetaAlgorithm__algorithm.percentile
31+
return self._MetaAlgorithm__algorithm.percentile # type: ignore

pydp/distributions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .._pydp._distributions import *
1+
from .._pydp._distributions import * # type: ignore

pydp/util/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .._pydp._util import *
1+
from .._pydp._util import * # type: ignore

tests/base/test_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import pytest
2-
import pydp as dp
1+
import pytest # type: ignore
2+
import pydp as dp # type: ignore
33

44
# TODO: Check whether we should delete logging public binding or allow it
55
pytestmark = pytest.mark.skip(reason="we do not return allow user to set up logging.")

tests/base/test_percentile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import pytest
2-
import pydp as dp
1+
import pytest # type: ignore
2+
import pydp as dp # type: ignore
33

44
# TODO: check whether to delete this test suit or update it
55
pytestmark = pytest.mark.skip(

0 commit comments

Comments
 (0)